12. desktop picture設定 05.改訂版2013-10-05

05.スクリプトのバージョンアップ?です。
擬似的undo機能、複数画像選択時にはブラウズモード。
また画像ファイル選択時のみ動作するようにしました。
「メモ書き倉庫」さんから拝借したgetModifierKeysハンドラは内蔵仕様に。

拙作スクリプトは以下。アプリにされた後、お好みのアイコンを付けて、フォルダウィンドウのツールバーに登録して使う勝手が良いと思います。

property HomePict : ""
property PrevPict : ""

on setDTP(xxx)
tell application "System Events"
tell current desktop
if picture rotation = 1 then
set picture rotation to 0
end if
try
set PrevPict to picture as alias
end try
set picture to xxx as alias
end tell
end tell
end setDTP

on browseDTP(xxx)
tell application "System Events"
tell current desktop
if picture rotation = 1 then
set picture rotation to 0
end if
set currentpict to picture
repeat with pictitem in xxx
set picture to pictitem as alias
delay 4
end repeat
set picture to currentpict
end tell
end tell
end browseDTP

on getModifierKeys()
set theRubyScript to "require 'osx/cocoa';
event=OSX::CGEventCreate(nil);
mods=OSX::CGEventGetFlags(event);
print mods,' ';
print 'shift ' if (mods&0x00020000)!=0;

"
return do shell script "/usr/bin/ruby -e " & quoted form of theRubyScript
end getModifierKeys

tell application "Finder"
if my getModifierKeys() contains "shift" then
if (selection is not {}) then
set HomePict to selection as alias
set ppp to name of HomePict
display dialog "Home Picture set to " & ppp giving up after 2
my setDTP(HomePict)

else
set ppp to name of HomePict
display dialog "Back to Home Picture " & ppp giving up after 2
my setDTP(HomePict)
end if
else
if (selection is not {}) then
set tgtpicts to selection as alias list
if (count of tgtpicts) = 1 then
set tgtpict to selection as alias
--PDFなど追加あれば下記書き換えてください
if ((kind of tgtpict = "JPEG document") or (kind of tgtpict = "PNG document")) then
my setDTP(tgtpict)
else
return
end if
else

my browseDTP(tgtpicts)
end if
else
set ppp to name of PrevPict
display dialog "Back to Previous Picture " & ppp giving up after 2
my setDTP(PrevPict)

end if
end if
end tell

動作はスクリプトの内容順に、起動時に
・シフトキーを押しながら画像選択→Home Pictureとして設定
・シフトキーを押しながら何もファイル選択無し→Home Pictureへ復帰
・単純に画像選択→通常のdesktop pictureとして設定
・何もファイル選択無し→直前の設定画像へ戻る(undo)
・単純に複数画像選択→ブラウズモード
ブラウズモードの表示時間は、desktop pictureが換わる度にFinderがキャッシュを変更するので、あまり短くない方がいいでしょう。
フォルダウィンドウのツールバーからアプリ起動時に併用できるModifierKeyはshiftキーだけのようで、本作が目一杯という感じでしょうか。

コメント

コメントをどうぞ

※メールアドレスとURLの入力は必須ではありません。 入力されたメールアドレスは記事に反映されず、ブログの管理者のみが参照できます。

※なお、送られたコメントはブログの管理者が確認するまで公開されません。

名前:
メールアドレス:
URL:
コメント:

トラックバック

このエントリのトラックバックURL: http://darzilin.asablo.jp/blog/2013/10/05/7000541/tb

※なお、送られたトラックバックはブログの管理者が確認するまで公開されません。