Skip to content

Instantly share code, notes, and snippets.

@uchcode
uchcode / nsapp_servicesmenu_example.js
Created June 3, 2016 03:18
NSApp.servicesMenu in JXA
#!/usr/bin/osascript -l JavaScript
ObjC.import('Cocoa')
function MainMenu() {
function MenuItem(title, action, key) {
return $.NSMenuItem.alloc.initWithTitleActionKeyEquivalent(title, action, key)
}
@uchcode
uchcode / JXA-WebView.js
Created December 31, 2016 06:57
JXA (JavaScript for Automation) WebView applet template.
ObjC.import('Cocoa')
ObjC.import('WebKit')
MyWindow = WebViewWindow('http://www.youtube.com/')
MyWindow.makeKeyAndOrderFront(null)
//=====================================================================
function Window(x, y, width, height) {
let r = $.NSMakeRect(x, y, width, height)
@uchcode
uchcode / jxa-snippets.js
Last active September 10, 2023 19:16
JXA (JavaScript for Automation) snippets for applet.
function MenuItem(title, action, target) {
if (!title && !action && !target) return $.NSMenuItem.separatorItem
let i = $.NSMenuItem.alloc.init
i.title = title
i.action = action
i.target = target
return i
}
function StatusItem() {
@uchcode
uchcode / safariview.swift
Created March 28, 2020 15:55
SwiftUI with UIViewController Design Pattern.
import SwiftUI
import SafariServices
struct DemoView: View, Hostable {
@EnvironmentObject var hostedObject: HostingObject<DemoView>
var address: String = "https://example.com"
func present() { // UIKit code
let safari = SFSafariViewController(url: URL(string: address)!)
@uchcode
uchcode / PHPwebserver.js
Last active May 10, 2023 14:31
JXA (JavaScript for Automation) DockMenu applet example.
ObjC.import('Cocoa')
App = Application.currentApplication()
App.includeStandardAdditions = true
const RESOURCE = $.NSBundle.mainBundle.resourcePath.js
const HOST = 'localhost'
const PORT = 8080
const ADDR = `${HOST}:${PORT}`
const DIR = `${RESOURCE}/public_html/`
@uchcode
uchcode / jxa_status_bar_app.js
Created March 13, 2016 18:57
Statusbar App in JXA
#!/usr/bin/osascript -l JavaScript
ObjC.import('Cocoa')
app = Application.currentApplication()
app.includeStandardAdditions = true
ObjC.registerSubclass({
name: 'MenuAction',
methods: {
@uchcode
uchcode / Create-standalone-Mac-OS-X-applications-with-Python.md
Last active February 8, 2023 05:05
PythonでスタンドアロンのMac OS Xアプリケーションを作成する

PythonでスタンドアロンのMac OS Xアプリケーションを作成する

Pythonのプログラムを配布可能なアプリケーションを作成する方法について扱います。

Pythonプログラムの実行方式

コンピュータが理解できるのは突き詰めると、0と1だけです。そのため、プログラムを実行するには「プログラミング言語で書かれたテキストのプログラム」を0と1に変換する必要があります。そのやり方には2つあり、ひとつはコンパイラを使うもので、もうひとつはインタプリタを使うものです。

以下に両者の違いについて記載します。

@uchcode
uchcode / ImageViewer.swift
Last active January 11, 2023 10:49
Developing a Document-Based App in SwiftUI
import SwiftUI
struct ContentView: View {
@ObservedObject var browser = { () -> DocumentBrowserObject in
let dbo = DocumentBrowserObject (
forOpeningFilesWithContentTypes: [
"public.png",
"public.jpeg"
]
)
@uchcode
uchcode / SoundcloudStatusBar.js
Created December 31, 2016 16:57
JXA (JavaScript for Automation) StatuBar applet example.
ObjC.import('Cocoa')
ObjC.import('WebKit')
App = Application.currentApplication()
App.includeStandardAdditions = true
MyAction = SimpleSubclass('Action', {
quit(sender) {
App.quit()
},
@uchcode
uchcode / pyobjc_scriptingbridge.md
Last active June 19, 2022 14:44
PythonでMacスクリプティング

PythonでMacスクリプティングの例

現在、iTunesで再生している曲名を取得。

#!/usr/bin/python
# -*- coding: utf-8 -*-

from ScriptingBridge import *