applescript

SomaFm

~/bin/somafm #!/bin/sh play() { osascript -e 'tell app "iTunes" to open location "'${1}'"' echo "play [ ${2} ]" } case $1 in stop) osascript -e 'tell app "iTunes" to stop' echo 'iTunes stop.' ;; help) echo "Usage: $0 {|help|stop|jazz|goa}"…

ブラウザをリロード

Safari osascript -e 'tell app "Safari"' -e 'activate' -e 'do JavaScript "window.location.reload();" in first document' -e 'end tell' Firefox System Eventsを使うので、「システム環境設定 -> ユニバーサルアクセス」の「補助装置にアクセスできる…

元々アクティブであるアプリケーションをアクティブ

set lastApp to (path to frontmost application as string) -- なんかの処理 tell application lastApp to activate

パッケージしてインストール

ドロップしたフォルダに'.wdgt'をつけて、dashboardにインストールする。 やっつけ on open theList set thePath to POSIX path of (item 1 of theList as string) set theSrc to thePath set tmp to AppleScript's text item delimiters set AppleScript's …

ストリーミングの情報

applescript tell application "iTunes" current stream title -- the name of the current song in the playing stream name of current track -- the URL of the playing stream or streaming web site end tell shell script #!/bin/sh # osascript -e 't…

一意のプレイリストを再生

property thePlaylist : "IndiePopRocks" tell application "iTunes" launch stop set the_playlist to user playlist thePlaylist set view of front window to the_playlist play the_playlist end tell そのシェルスクリプト版 #!/bin/sh PLAY_LIST='Indi…

シンタックス

applescript.vim - Syntax highlighting for AppleScript : vim online

applescriptに引数を渡す

a.scpt on run argv return "hello, " & item 1 of argv & "." end run実行 % osascript a.scpt world hello, world.

Synergys with Growl

set theConfFile to "~/.synergy_home.conf" try set thePid to do shell script ("/bin/ps -x|grep synergys| grep -v grep|perl -ne '/^\\s*(\\d+)\\s+/;print $1;'") do shell script ("/bin/kill " & thePid) on error end try try -- 会社は有線 set is…

ドロップレットでファイルを新規タブで開く

splhack: vim7.1.100 property CR : ASCII character of 13 property ESC : ASCII character of 27 on open theList set thePath to POSIX path of (item 1 of theList as string) --display dialog thePath tell application "Vim" to activate tell applic…

FirefoxとParallels

Firefoxが起動してない時に tell application "Firefox"するとParallels内のFirefoxを起動しようとするので、 if ( isRunFs() ) then tell application "Firefox" -- 処理 end tell else display dialog { "try again." } -- つづけて処理をしようとすると -…

php4とphp5の切り替え(その2)

~/.pearrcを差し替える /usr/local/phpにsymlinkを張り直す。 apacheを再起動させる property PEAR_RC : "/path/to/.pearrc" property PHP_DIR : "/path/to/php" property PHP_CURRENT : PHP_DIR --& "current" property PHP : PHP_CURRENT & "/bin/php" pro…

サーバへ接続...

property SMB : "smb://WORKGROUP;user:pass@COMPUTER_NAME/path/to/dir" tell application "Finder" mount volume SMB activate -- なんとなく end tell

インプットメソッド切替

むちゃ遅 むちゃ環境依存(日頃、cmd+spaceを使用してる人向け) より詳しくは、 defaults -currentHost read com.apple.HIToolbox AppleCurrentInputSourceして"Input Mode"で種別を判断する。 applescript版 property ROMAN : "smRoman" set IM to do shel…

php-doc.mi?

php-doc.vimの中途半端なパクリ phpdoc を挿入してくれるスクリプト - 呆備録 property TYPE_MIXED : "mixed" property TYPE_BOOL : "bool" property TYPE_ARRAY : "array" property TYPE_STR : "string" on run tell application "mi" tell document 1 set …

php4とphp5の切り替え

property PHP5 : "path/to/php5" property PHP4 : "path/to/php4" property PHP_DIR : "/usr/local/php/" property PHP_CURRENT : PHP_DIR & "current" property PHP : PHP_CURRENT & "/bin/php" property USER : "oppara" property PASS : "pass" property …

MTASCでシンタックスチェック

MTASC http://www.mtasc.org/#download インストール $ unzip ~/download/mtasc-1.12-osx.zip $ sudo mv ~/download/mtasc-1.12-osx /usr/local/. $ sudo ln -s /usr/local/mtasc-1.12-osx /usr/local/mtasc $ vi ~/.bashrc $ source ~/.bashrc $ mtasc -h m…

Synergysの再起動

動けばOK牧場 ?はバックスラッシュ set theConfFile to "~/.synergy_home.conf" set theOfficeIp to "xxx.xxx.xxx.xxx" try set theCmd to "ps -x|grep synergys|grep -v grep|" set theCmd to theCmd & "perl -ne '/^??s*(??d+)??s+/;print $1;'" set thePi…

自分のいるディテクトリを返す

getCwd(path to me) on getCwd(thePathToMe) set thePath to POSIX path of ((thePathToMe) as string) as string set theCwd to do shell script "perl -e '?"" & thePath & "?"=~ m@^(.+/).+/?@;print $1;'" return theCwd as string end getCwd

ファイル指定まとめ

俺々ルール POSIXパスの文字列で取り扱う。 ディレクトリは"/"で終わる。 "/hoge/moge/" -- ディレクトリ "hoge/moge" -- ファイル パッケージ化されたファイルをfileパスに変換するとディレクトリ扱いになる(あたりまえ) "/hoge/moge.app" as POSIX file …

script editorを使ってコンパイル

on writePropAndSaveAppBundle(theProp, theSrcPath, theDestPath) if isExistsItem(theDestPath) = false then do shell script "touch " & theDestPath end if tell application "Script Editor" activate open theSrcPath as POSIX file if theProp is no…

とにかくposixパスの文字列をかえす

on getPosixStr(theItem) if class of theItem is string then if theItem contains ":" then return (POSIX path of theItem) as string else return theItem end if else if class of theItem is Unicode text then return theItem as string else return …

osacompile

詳しくは、man osacompile $ osacompile -o 保存するファイルのパス 読み込むファイルのパス保存するファイルを*.appにするとアプリケーションバンドルで保存される。 (ScriptEditorで保存したのとInfo.plistがちょっと違う) 読み込むファイルは、*.scptで…

ドロップレットからshell scriptに渡す前処理

on open theList set thePath to POSIX path of (item 1 of theList as string) display dialog thePath end open `

1ボタンのみのdisplay dialog

-- okボタンのみ on dispOk(theMessage) display dialog (theMessage) buttons {"OK"} default button "OK" giving up after 20 end dispOk -- cancelボタンのみ on dispError(theMes) display dialog theMes buttons {"Cancel"} default button 1 end dispE…

指定フォルダ内の拡張子がtheExtensionなファイルリストの取得

on getFileList(thePosixPath, theExtension) set theList to {} set theFilePath to thePosixPath as POSIX file set theFileList to list folder theFilePath repeat with curItem in theFileList if curItem contains theExtension then set end of theLi…

ファイル、フォルダの存在確認

そのまんまがあった...orz tell application "Finder" exists 参照 ende tell on isExistItem(thePosixPath) try set theFilePath to thePosixPath as POSIX file set theAliasPath to theFilePath as alias return true on error return false end try end …