| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 004 | (* |
| 005 |
|
| 006 | ショートカット(Shortcuts)用 |
| 007 |
|
| 008 | 不可視ファイルの表示有無 |
| 009 | デスクトップの有無の変更 |
| 010 |
|
| 011 | com.cocolog-nifty.quicktimer.icefloe *) |
| 012 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 013 | ##自分環境がos12なので2.8にしているだけです |
| 014 | use AppleScript version "2.8" |
| 015 | use framework "Foundation" |
| 016 | use scripting additions |
| 017 |
|
| 018 |
|
| 019 |
|
| 020 |
|
| 021 | set strItem1 to ("【有】不可視ファイル") as text |
| 022 | set strItem2 to ("【無】不可視ファイル") as text |
| 023 | set strItem3 to ("【有】デスクトップ") as text |
| 024 | set strItem4 to ("【無】デスクトップ") as text |
| 025 |
|
| 026 | set listSelection to {strItem1, strItem2, strItem3, strItem4} as list |
| 027 | set strOK to ("設定変更") as text |
| 028 | set strCancel to ("キャンセル") as text |
| 029 | set strTitle to ("処理を選んでください") as text |
| 030 | set strPrompt to ("実行する処理を選んでください" & return & "Finderが再起動します") as text |
| 031 |
|
| 032 | set strCmd to ("/usr/bin/defaults read com.apple.finder CreateDesktop") as text |
| 033 | try |
| 034 | set numBool to (do shell script strCmd) as integer |
| 035 | on error strErrMes number numErrNo |
| 036 | log strErrMes & numErrNo |
| 037 | set numBool to 1 as integer |
| 038 | end try |
| 039 | if numBool is 1 then |
| 040 | set numListNo to (last item of listSelection) |
| 041 | else |
| 042 | set numListNo to (third item of listSelection) |
| 043 | end if |
| 044 |
|
| 045 |
|
| 046 | try |
| 047 | tell application "System Events" |
| 048 | activate |
| 049 | set valueResponse to (choose from list listSelection with title strTitle with prompt strPrompt default items numListNo OK button name strOK cancel button name strCancel with empty selection allowed without multiple selections allowed) |
| 050 | end tell |
| 051 | on error strErrMes number numErrNo |
| 052 | log strErrMes & numErrNo |
| 053 | return false |
| 054 | end try |
| 055 | if (class of valueResponse) is boolean then |
| 056 | error "ユーザによってキャンセルされました。" number -128 |
| 057 | else if (class of valueResponse) is list then |
| 058 | if valueResponse is {} then |
| 059 | error "Error 何も選んでいません" number -128 |
| 060 | else |
| 061 | set strResponse to (first item of valueResponse) as text |
| 062 | end if |
| 063 | end if |
| 064 |
|
| 065 |
|
| 066 |
|
| 067 | if strResponse is strItem1 then |
| 068 | set strCmd to ("/usr/bin/defaults write com.apple.finder AppleShowAllFiles -bool true") as text |
| 069 | else if strResponse is strItem2 then |
| 070 | set strCmd to ("/usr/bin/defaults write com.apple.finder AppleShowAllFiles -bool false") as text |
| 071 | else if strResponse is strItem3 then |
| 072 | set strCmd to ("/usr/bin/defaults write com.apple.finder CreateDesktop -bool true") as text |
| 073 | else if strResponse is strItem4 then |
| 074 | set strCmd to ("/usr/bin/defaults write com.apple.finder CreateDesktop -bool false") as text |
| 075 | end if |
| 076 |
|
| 077 | try |
| 078 | do shell script strCmd |
| 079 | on error strErrMes number numErrNo |
| 080 | log strErrMes & numErrNo |
| 081 | #エラーしたら 不可視無し デスクトップ有りに変更する |
| 082 | delay 1 |
| 083 | set strCmd to ("/usr/bin/defaults write com.apple.finder AppleShowAllFiles -bool false") as text |
| 084 | do shell script strCmd |
| 085 | delay 1 |
| 086 | set strCmd to ("/usr/bin/defaults write com.apple.finder CreateDesktop -bool true") as text |
| 087 | do shell script strCmd |
| 088 | end try |
| 089 |
|
| 090 | # Finder再起動 |
| 091 | set strCmd to ("/usr/bin/killall Finder") as text |
| 092 |
|
| 093 |
|
| 094 | try |
| 095 | do shell script strCmd |
| 096 | on error strErrMes number numErrNo |
| 097 | log strErrMes & numErrNo |
| 098 | #エラーしたら通知 |
| 099 | tell application "System Events" |
| 100 | activate |
| 101 | display alert "設定変更でエラーになりました" |
| 102 | end tell |
| 103 | return false |
| 104 | end try |
| 105 |
|
| 106 | return true |