2016-11-11 1 views
0

としてエクスポート相対パスは、私はそれがでログ上で実行する必要があるので、私はの.appファイルとしてAppleScriptをエクスポートした.APP

これは私のコードです:。

repeat 
    tell application "System Events" 
     repeat with desktopNumber from 1 to count of desktops 
      tell desktop desktopNumber 
       set picture to "~/Desktop/script/img.jpg" 
      end tell 
     end repeat 
    end tell 
end repeat 

パスへスクリプトは〜/ Desktop/script/script.app/Contents/Resources/Scripts/main.scptです

私はリソースフォルダに画像を置いて、相対パスを作成したいので、私のスクリプトを変更しないでどこでもフォルダを試しました。

set desktopPicture to ((container of container of (path to me)) as text) & "/img.jpg" 
repeat 
    tell application "System Events" 
     repeat with desktopNumber from 1 to count of desktops 
      tell desktop desktopNumber 
       set picture to desktopPicture 
      end tell 
     end repeat 
    end tell 
end repeat 

しかし、それはエラーCan’t make container of container of alias \"Macintosh HD:Users:Me:Desktop:script:script.app:Contents:Resources:Scripts:main.scpt\" into type text.

答えて

0

System Eventsはチルダ~を拡大することができない私を与えます。

あなたは相対パスを使用して~/Desktop/script/img.jpgを参照したい場合は、

tell application "System Events" to set desktopPicture to file "img.jpg" of folder "script" of desktop folder 

または

set desktopPicture to alias ((path to desktop folder as text) & "script:img.jpg") 

を使用することができますが、ファイルが存在しない場合は、両方のケースではAppleScriptがエラーをスローすることを考えてみましょう。

関連する問題