Skip to content

Instantly share code, notes, and snippets.

@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 / CurrencyConverter.js
Last active December 31, 2016 08:13
JXA (JavaScript for Automation) Window applet example.
ObjC.import('Cocoa')
class UserInterface {
constructor() {
this.lateLabel = Label(10, 110, 160, 26); {
this.lateLabel.alignment = $.NSRightTextAlignment
this.lateLabel.stringValue = 'Exchange Rate per $1:'
}
this.dollersLabel = Label(10, 80, 160, 26); {
this.dollersLabel.alignment = $.NSRightTextAlignment
@uchcode
uchcode / jxa-snippets.js
Last active March 6, 2025 22:14
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 / JXA-DockMenu.js
Last active December 31, 2016 08:09
JXA (JavaScript for Automation) DockMenu applet template.
ObjC.import('Cocoa')
App = Application.currentApplication()
App.includeStandardAdditions = true
MyAction = SimpleSubclass('Action', {
mewmew(sender) {
App.displayAlert('🐱 mew mew')
},
quit(sender) {
@uchcode
uchcode / JXA-StatuBar.js
Last active December 31, 2016 08:08
JXA (JavaScript for Automation) StatuBar applet template.
ObjC.import('Cocoa')
App = Application.currentApplication()
App.includeStandardAdditions = true
MyAction = SimpleSubclass('Action', {
mewmew(sender) {
App.displayAlert('🐱 mew mew')
},
quit(sender) {
@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-Window.js
Last active August 4, 2020 00:08
JXA (JavaScript for Automation) Window applet template.
ObjC.import('Cocoa')
function UserInterface() {
this.okButton = Button(300, 10, 90, 26); {
this.okButton.title = 'OK'
}
this.cancelButton = Button(210, 10, 90, 26); {
this.cancelButton.title = 'Cancel'
this.cancelButton.keyEquivalent = '\u{1b}'
}
@uchcode
uchcode / file0.txt
Created December 23, 2016 14:38
Ruby FFI bindings for the OSX Cocoa API を使うと楽にMacアプリが書ける ref: http://qiita.com/tom-u/items/b5ea665c1df37f6f3bcb
brew install ruby
@uchcode
uchcode / DoShellScript.js
Created December 23, 2016 05:55
NSUserUnixTaskでJXAスクリプトを実行して結果を得る ref: http://qiita.com/tom-u/items/ba051dee2a6a7a4a204a
#!/usr/bin/osascript
delay(3) //歯車アイコン確認用
App = Application.currentApplication()
App.includeStandardAdditions = true
App.doShellScript('ls ~/', {alteringLineEndings:false})
@uchcode
uchcode / path-to-me.swift
Created December 23, 2016 02:16
[Swift] スクリプトが存在するディレクトリを絶対パスで取得する ref: http://qiita.com/tom-u/items/4c441d94f02b9e7e6c2d
#!/usr/bin/env swift
import Foundation
guard let pathToMe = URL(string: "\(#file)", relativeTo: URL(fileURLWithPath: FileManager.default.currentDirectoryPath))?.path else {
print("Error: current path of #file")
exit(-1)
}
print( "path to me: \(pathToMe)" ) // path to me: /Users/uchcode/Desktop/path-to-me.swift