Skip to content

Instantly share code, notes, and snippets.

@uchcode
uchcode / in-out-example1.js
Created June 30, 2017 12:58
JXAで標準入出力、エラー、パスワード入力、ログ出力 ref: http://qiita.com/tom-u/items/65d07ff6e6775853c6de
m = 'stdout: think different'
t = '\n'
u = $.NSUTF8StringEncoding
d = $(m+t).dataUsingEncoding(u)
$.NSFileHandle.fileHandleWithStandardOutput.writeData(d)
@uchcode
uchcode / write-read-example1.js
Last active July 1, 2017 05:16
JXA でテキストファイルを読み書きする四つの方法 ref: http://qiita.com/tom-u/items/1bf59eb6dc9ff77be7e9
app = Application.currentApplication()
app.includeStandardAdditions = true
path = app.pathTo("desktop",{from:"user domain"})+"/read_write.txt"
// write
contents = new Date() + " 本日は晴天なり"
try {
f = app.openForAccess(path, {writePermission:true})
app.setEof(f, {to:0})
@uchcode
uchcode / AppletKit.js
Created June 17, 2017 01:59
AppletKit.js
ObjC.import('Cocoa')
function Url(str) {
return $.NSURL.URLWithString(str)
}
function Req(url) {
return $.NSURLRequest.requestWithURL(url)
}
@uchcode
uchcode / mac_applet_by_jxa.js
Last active June 17, 2017 01:36
mac applet by jxa example
eval($.NSString.stringWithContentsOfFileEncodingError($('~/Library/Script Libraries/AppletKit.js').stringByStandardizingPath.js,$.NSUTF8StringEncoding,$()).js)
ObjC.import('Cocoa')
controls = {}
UtilityWindow('AppWindow', {
setup() {
this.setFrameDisplayAnimate($.NSMakeRect(0, 0, 200, 200), false, false)
this.center
@uchcode
uchcode / finder_frontmost_visible_window_path.py
Last active June 7, 2017 13:49
pyobjc: get visible window path of finder
# -*- coding: utf-8 -*-
import os
from urlparse import urlparse
from urllib import unquote
from ScriptingBridge import SBApplication
def finder_frontmost_visible_window_path():
finder = SBApplication.applicationWithBundleIdentifier_('com.apple.Finder')
windows = filter(lambda x:x.visible()==True, finder.windows())
if windows:
@uchcode
uchcode / Create-standalone-Mac-OS-X-applications-with-Python.md
Last active February 5, 2025 15:20
PythonでスタンドアロンのMac OS Xアプリケーションを作成する

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

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

Pythonプログラムの実行方式

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

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

@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 *
@uchcode
uchcode / hello_world.py
Last active May 22, 2018 09:37
pyobjc example.
#!/usr/bin/python2.6
# -*- coding: utf-8 -*-
import objc
from Foundation import *
from AppKit import *
from PyObjCTools import AppHelper
NSWindowDelegate = objc.protocolNamed("NSWindowDelegate")
@uchcode
uchcode / YouTubeApp
Created January 21, 2017 18:24
JXAでメニューバーアプリ ref: http://qiita.com/tom-u/items/0926b511f99b0dcad785
ObjC.import('Cocoa')
ObjC.import('WebKit')
var webViewRect = $.NSMakeRect(0, 0, 1024, 560)
var webViewConf = $.WKWebViewConfiguration.alloc.init
webViewConf.preferences.plugInsEnabled = true
var webView = $.WKWebView.alloc.initWithFrameConfiguration(webViewRect, webViewConf)
var url = $.NSURL.URLWithString('http://www.youtube.com/')
var req = $.NSURLRequest.requestWithURL(url)
@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()
},