AutomatorでApplescriptを書き書き

Finderのサービスに追加して、wineを走らせるためのコードを書いた。

とりあえず、動くだけクオリティ。

 

-----(コード開始)-------------------------

on run {input}
    tell application "Terminal"
       
        #引数からUnix用のファイルパスを取得
        try
            set unipath to quoted form of ((POSIX path of input) as Unicode text)
        on error
            display alert "Please select something." as critical buttons {"OK"}
            return
        end try
       
        #コメントアウト:activate
       
        #実行するコマンドラインの作成
        set doCmd1 to "date;echo Begin Wine." as Unicode text
        set doCmd2 to "wine " & unipath & "&" as Unicode text
        set doCmd3 to "date;echo End Wine." as Unicode text
       
        #Terminalのウィンドウの存在有無の判定後、コマンド実行
        set wCnt to count (every window whose visible is true)
        if wCnt = 0 then
            do script doCmd1
        else
            do script doCmd1 in front window
        end if
            do script doCmd2 in front window
            do script doCmd3 in front window
       
    end tell
end run

 

-----(コード終了)-------------------------


スクリプトだけならScript Editorの方が書き易い、と思った。

MacユーザにWindowsのインストーラーを送ってくる人の為に苦労しています。