GUIã¹ã¯ãªããã£ã³ã°ãªAppleScriptç°å¢ãå¿«é©ã«ãã
GUIã¹ã¯ãªããã£ã³ã°ã¯ã¨ã£ã¦ã便å©ã ãããã¯OSãæä½ããAppleScriptã¨è¨ããã®ã§ãåºæ¬çã«ãã¦ã¹ããã¼ãã¼ãã®æä½ãªãä½ã§ãæä½ã§ããå¯è½æ§ãç§ãã¦ããã
ããããã¡ãã¥ã¼ãã·ã§ã¼ãã«ãããã¼ãæä½ããã®ã¯æå¤ã¨å¤§å¤ãæä½ããã¾ã§ã®äºåã®æé ãæ¸ãæ¹ãç ©éã ã£ãããã¡ãã£ã¨ãããã¨ã§æä½ã§ããªãç¶æ ã«ããé¥ã...ããã£ã¨ã·ã³ãã«ã«ã確å®ã«æä½ã§ããç°å¢ãæã«å ¥ãããã®ã ï¼
åºæ¬
- ä¾ï¼é¸æé
ç®ãSpotlightæ¤ç´¢ãã
- ãã¼ã¯ã¼ããã³ãã¼ï¼ãã¼ã¹ãããããã¯ãé¸æä¸ã®æååããã®ã¾ã¾ãã¼ã¯ã¼ãã«ãªãã°ãã£ã¨å¹¸ãã«ãªããã¨æã£ã¦ã
(*ãã¡ã¤ã«åï¼spotlight_with_selection.scpt*) delay 0.5 --Quicksilverããå©ç¨ããæã¯ããã®ã²ã¨å¼å¸ãå¿ è¦ tell application "System Events" --ã·ã§ã¼ãã«ããæä½ãããéããGUIã¹ã¯ãªããã£ã³ã°ã¯ç¡å¹ã§ãåä½ãã --tell application "APP_NAME" to activate--å¿ è¦ã«å¿ãã¦ãã¢ããªã±ã¼ã·ã§ã³"APP_NAME"ãã¢ã¯ãã£ãã«ãã keystroke "c" using {command down} --command-C ï¼ã³ãã¼ï¼ keystroke space using {control down} --command-space ï¼Spotlightã®èµ·åï¼ delay 0.1 --ã·ã§ã¼ãã«ãããé£æºãããæã«ãã²ã¨å¼å¸ãå¿ è¦ãªå ´åããã keystroke "v" using {command down} --command-V ï¼ãã¼ã¹ãï¼ end tell
- ä¾ï¼ã¡ã¼ã«ãéä¿¡ããæã«ã¨ã³ã³ã¼ããèªåã«è¨å®ãã
- ã¡ã¼ã«ãè¿ä¿¡ããæã®éä¿¡æ¸ã¿ã¡ã¼ã«ã®æååããèªåçã«è§£æ¶ãããèªåã§æ¸ããã¡ã¼ã«ãæååããããªãã¦å ªããããªã...ã
(*ãã¡ã¤ã«åï¼mail_encoding_auto.scpt*) on adding folder items to this_folder after receiving added_items
tell application "Finder" to open added_items tell application "System Events" tell process "Mail" set frontmost to true keystroke "1" using {command down, option down} --èªå keystroke "w" using {command down} click menu item "ã¡ãã»ã¼ã¸ãã¥ã¼ã¢" of menu "ã¦ã¤ã³ãã¦" of menu bar item "ã¦ã¤ã³ãã¦" of menu bar 1 keystroke "w" using {command down} keystroke "n" using {command down, option down} end tell end tell end adding folder items to
親åãã¼ã¸ã§ã³
- ãããã·ã¹ãã ç°å¢è¨å® >> ã¦ããã¼ãµã«ã¢ã¯ã»ã¹ >> è£å©è£ ç½®ã«ã¢ã¯ã»ã¹ã§ããããã«ãã ã«ãã§ãã¯ããªãã¨GUIã¹ã¯ãªããã£ã³ã°ãåããæ©ããã¨ã«ãªãã
- ã ããã以ä¸ã®ãããªãã§ãã¯ããã¦ããã¨ã人ã«åªããã¹ã¯ãªããã«ãªãã
delay 0.5 --Quicksilverãå©ç¨ããæã¯ããã®ã²ã¨å¼å¸ãå¿ è¦ tell application "System Events" if UI elements enabled then --ã·ã§ã¼ãã«ããæä½ãããéããGUIã¹ã¯ãªããã£ã³ã°ã¯ç¡å¹ã§ãåä½ãã --æä½å¯¾è±¡ã®ã¢ããªãæåé¢ã«è¨å®ãã(ã¹ã¯ãªããã¡ãã¥ã¼ããå®è¡ããå ´åå¿ è¦) tell process "Mail" set frontmost to true keystroke "1" using {command down, option down} --èªå keystroke "w" using {command down} click (menu item "ã¡ãã»ã¼ã¸ãã¥ã¼ã¢" of menu "ã¦ã¤ã³ãã¦" of menu bar item "ã¦ã¤ã³ãã¦" of menu bar 1) delay 0.1 --ã·ã§ã¼ãã«ãããé£æºãããæã«ãã²ã¨å¼å¸ãå¿ è¦ãªå ´åããã keystroke "w" using {command down} keystroke "n" using {command down, option down} end tell else tell application "System Preferences" activate set current pane to pane "com.apple.preference.universalaccess" set msg to "GUIã¹ã¯ãªããã£ã³ã°ãå©ç¨å¯è½ã«ãªã£ã¦ãã¾ããã\n\"è£å©è£ ç½®ã«ã¢ã¯ã»ã¹ã§ããããã«ãã\" ã«ãã§ãã¯ãå ¥ãã¦ç¶ãã¾ããï¼" display dialog msg buttons {"ãã£ã³ã»ã«", "ãã§ãã¯ãå ¥ãã¦ç¶ãã"} with icon note end tell set UI elements enabled to true delay 1 tell application "System Preferences" to quit delay 1 end if end tell
- ä¸è¨ãéå½¢ã¨ãã¦ããã¨ã¯ tell process "xxxx" ã end tell ãããã¯å ãå¿ è¦ãªã³ã¼ãã«ç½®ãæããã°è¯ãã®ã ãã
- æ¯åãã³ãã¼ï¼ãã¼ã¹ãããã¦æ¸ãæãã¦ããã®ã§ã¯ãé·æçã«ã¯ããã°ã©ãã«åªãããªãã
- ã³ã¼ãã®éè¤ãçãã¿ãä¿®æ£ããã¨ãã®ä¿®æ£ç®æã®å¤ãã«åè¦å «è¦ããã
- ã³ã¼ãã®è¦æ¸¡ããæªããå ¨ä½ãèªã¿é£ããªããï¼é·ã£ããããã³ã¼ãããã©ãã©ã¨ç¶ãã®ã§ï¼
ããã§ãæ©è½ãã¨ã«åå©ç¨ã§ããä¸è¬çãªé¨åã¨ãã¦åãåºãã¦ãããã¨ãéè¦ã«ãªãã
GUIã¹ã¯ãªããã£ã³ã°ã®ãã§ãã¯ãä¸è¬åãã
- GUIã¹ã¯ãªããã£ã³ã°ã®æå¹ã»ç¡å¹ããã§ãã¯ããé¨åã¯ãã»ã¨ãã©ä¿®æ£ç¡ãã§ã以ä¸ã®ããã«åãåºããã¨ãåºæ¥ãã
--GUIã¹ã¯ãªããã£ã³ã°ãç¡å¹ãªããæå¹ã«ãããã¨ãå§ããã¡ãã»ã¼ã¸ãåºåãã on check() tell application "System Events" if UI elements enabled is false then tell application "System Preferences" activate set current pane to pane "com.apple.preference.universalaccess" set msg to "GUIã¹ã¯ãªããã£ã³ã°ãå©ç¨å¯è½ã«ãªã£ã¦ãã¾ããã\n\"è£å©è£ ç½®ã«ã¢ã¯ã»ã¹ã§ããããã«ãã\" ã«ãã§ãã¯ãå ¥ãã¦ç¶ãã¾ããï¼" display dialog msg buttons {"ãã£ã³ã»ã«", "ãã§ãã¯ãå ¥ãã¦ç¶ãã"} with icon note end tell set UI elements enabled to true delay 1 tell application "System Preferences" to quit delay 1 end if end tell end check
- ããã§ãGUIã¹ã¯ãªããã£ã³ã°ãå©ç¨ããç´åã«ãã·ã³ãã«ã«check()ãã³ãã©ãå¼ã³åºãã ãã§OKã
ã¡ãã¥ã¼æä½ã便å©ã«ãã
- ã¡ãã¥ã¼æä½ã®ãã¤ã³ãã¯ãå®éã«ã¡ãã¥ã¼æä½ãè¡ã以ä¸ã®ã³ã¼ãé¨åã
click menu item "ã¡ãã»ã¼ã¸ãã¥ã¼ã¢" of menu "ã¦ã¤ã³ãã¦" of menu bar item "ã¦ã¤ã³ãã¦" of menu bar 1
- of ãå©ç¨ãã表ç¾ã¯è¦é£ãã®ã§ã以ä¸ã®ããã« 's ãå©ç¨ããéé ã®è¡¨ç¾ã«å¤å½¢ãã¦ã¿ãã
click menu bar 1's menu bar item "ã¦ã¤ã³ãã¦"'s menu "ã¦ã¤ã³ãã¦"'s menu item "ã¡ãã»ã¼ã¸ãã¥ã¼ã¢"
- ããã¦ãæä½ããã¡ãã¥ã¼ã®é層ã«ãã£ã¦ãã³ã¼ã表ç¾ã¯ä»¥ä¸ã®ããã«å¤åãããï¼3é層ã¾ã§ããç·¨éã¡ãã¥ã¼ã®ä¾ã«å¤æ´ï¼
click menu bar 1's menu bar item "ç·¨é" --ç·¨é click menu bar 1's menu bar item "ç·¨é"'s menu "ç·¨é"'s menu item "æ¤ç´¢" --ç·¨é/æ¤ç´¢ click menu bar 1's menu bar item "ç·¨é"'s menu "ç·¨é"'s menu item "æ¤ç´¢"'s menu "æ¤ç´¢"'s menu item "次ãæ¤ç´¢" --ç·¨é/æ¤ç´¢/次ãæ¤ç´¢
- ã¤ã¾ãã1é層ç®ã®ã¡ãã¥ã¼ãã¼ã ãã¯ç¹æ®ã ãã©ã2é層ç®ä»¥éã¯åããã¿ã¼ã³ã®ç¹°ãè¿ããªã®ã ã
- æä½ãããæçµé層ã®'sãåé¤ããã°ããããã¡ãã¥ã¼ãæä½ããã³ã¼ãã«ãªãã
- ä¸è¨ã®ãããªä»çµã¿ã¯ç解ã§ããã®ã ãã人éãè¦ã¦ä¸ç®ã§åããæ¸ãæ¹ã¨ã¯è¨ããªã...ã
- çæ³ã¨ãã¦ã¯ã"ç·¨é/æ¤ç´¢/次ãæ¤ç´¢" ã®ãããªãã¹æååã§ã¡ãã¥ã¼æä½ãå®ç¾ãããã
- æåã¯ã¡ãã¥ã¼ãã¹ãä½å層ãããã確èªã㦠if ã§é層ãã¨ã«åãã¦å¯¾å¿ãã¦ã¿ãã
- ããããããã§ã¯æä½ããé層åã ã対å¿ããã³ã¼ããæ¸ãå¿
è¦ãããã
- ãããã5é層ãããã¾ã§å¯¾å¿ããã°ãã»ã¨ãã©ã®æä½ã¯åé¡ãªãã®ãããããªãã...ã
- ããã§ãã¡ãã£ã¨å·¥å¤«ãã¦ãæçµçã«ã¯ä»¥ä¸ã®ããã«ãã¦ã¿ããï¼ã¤ãã§ã«ãã¢ã¤ãã çªå·ã«ãããã¹æå®ã«ã対å¿ãããï¼
on click_menu(app_name, menu_path) if menu_path is "" then error "menu_path ãå ¥åããã¦ãã¾ããã" end if if app_name is "" then set app_name to frontmost_app() end if set mp to split(menu_path, "/") tell application "System Events" tell process app_name if "AppleScript Runner" is in my every_process() or frontmost is false then set frontmost to true end if if mp's length = 1 then menu bar 1's (menu bar item (my to_number(mp's item 1))) else --menu bar 1's menu bar item (mp's item 1)'s menu (mp's item 1) menu bar 1's (menu bar item (my to_number(mp's item 1)))'s menu 1 repeat with i from 2 to mp's length if i < mp's length then --result's menu item (mp's item i)'s menu (mp's item i) result's (menu item (my to_number(mp's item i)))'s menu 1 else result's (menu item (my to_number(mp's item i))) end if end repeat end if click result --click:ã¯ãªãã¯ããï¼pick:é¸æãã--ã»ã¼åçã ããã¢ã¤ã³ã³ã¡ãã¥ã¼ã«ã¯clickãå¿ é delay 0.1 --é£ç¶ãã¦ã¡ãã¥ã¼ãæä½ããæãã²ã¨å¼å¸å¿ è¦ end tell end tell end click_menu --èµ·åä¸ã®ã¢ããªã±ã¼ã·ã§ã³åããªã¹ãã§åå¾ãã on every_process() tell application "System Events" processes's name end tell end every_process --æåé¢ã®ã¢ããªã±ã¼ã·ã§ã³åãåå¾ãã on frontmost_app() tell application "System Events" set name_list to processes's name whose frontmost is true name_list's first item end tell end frontmost_app on split(sourceText, separator) if sourceText = "" then return {} set oldDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to {separator} set theList to text items of sourceText set AppleScript's text item delimiters to oldDelimiters return theList end split on to_number(str) try str as number on error str end try end to_number
- ããã§ã以ä¸ã®ããã«ãã®ãããã·ã³ãã«ã«æ¸ããããã«ãªã£ãï¼
click_menu("Mail", "ã¦ã¤ã³ãã¦/ã¡ãã»ã¼ã¸ãã¥ã¼ã¢") --以ä¸ã®ã³ã¼ãã¨åç (* tell application "System Events" tell process "Mail" set frontmost to true click menu item "ã¡ãã»ã¼ã¸ãã¥ã¼ã¢" of menu "ã¦ã¤ã³ãã¦" of menu bar item "ã¦ã¤ã³ãã¦" of menu bar 1 end tell end tell *)
ãã¼ãã¼ãã·ã§ã¼ãã«ããã便å©ã«ãã
- ãã¼æä½ã§ããä¸è¨ã¡ãã¥ã¼æä½ã¨åãããã«ãã·ã³ãã«ãªæ¸ãæ¹ã¨ä¾¿å©ãã追æ±ãã¦ã¿ãã
on shortcut(app_name, key_text) if key_text is "" or key_text is {} then error "key_text ãå ¥åããã¦ãã¾ããã" end if if (count of key_text) = 1 then set key_list to split(key_text's first item, "-") else set key_list to split(key_text, "-") end if set last_key to downcase(key_list's last item) set modifier_key to {} if "command" is in key_list then set modifier_key to modifier_key & command down if "option" is in key_list then set modifier_key to modifier_key & option down if "control" is in key_list then set modifier_key to modifier_key & control down if "shift" is in key_list then set modifier_key to modifier_key & shift down if last_key is "delete" then set last_key to 51 --delete else if last_key is "esc" then set last_key to 53 --esc else if last_key is "â" then set last_key to 123 --â else if last_key is "â" then set last_key to 124 --â else if last_key is "â" then set last_key to 125 --â else if last_key is "â" then set last_key to 126 --â else if last_key is "space" then set last_key to space else if last_key is "tab" then set last_key to tab else if last_key is "return" then set last_key to return else if last_key's length is 3 then try set last_key to last_key as number end try end if press_key(app_name, last_key, modifier_key) end shortcut --ãã¼æä½ãå®è¡ãã --å©ç¨ä¾ï¼ -- press_key("1", command down) -- press_key(126, command down) on press_key(app_name, normal_key, modifier_key) if app_name is "" then set app_name to frontmost_app() end if tell application "System Events" tell process app_name if "AppleScript Runner" is in my every_process() or frontmost is false then set frontmost to true end if if my is_number(normal_key) then key code normal_key using modifier_key else keystroke normal_key using modifier_key end if end tell end tell end press_key --èµ·åä¸ã®ã¢ããªã±ã¼ã·ã§ã³åããªã¹ãã§åå¾ãã on every_process() tell application "System Events" processes's name end tell end every_process --æåé¢ã®ã¢ããªã±ã¼ã·ã§ã³åãåå¾ãã on frontmost_app() tell application "System Events" set name_list to processes's name whose frontmost is true name_list's first item end tell end frontmost_app on do_ruby_script(ruby_code) set shell_code to "ruby -e \"puts(" & ruby_code & ")\"" do shell script shell_code end do_ruby_script on downcase(str) do_ruby_script("'" & str & "'.downcase") end downcase on split(sourceText, separator) if sourceText = "" then return {} set oldDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to {separator} set theList to text items of sourceText set AppleScript's text item delimiters to oldDelimiters return theList end split on is_number(num) if num = {} or num = "" then false else (count of num) is 0 end if end is_number
- ããã§ã以ä¸ã®ããã«ã·ã³ãã«ã«æ¸ããããã«ãªã£ãï¼
shortcut("Mail", "command-option-N") --以ä¸ã®ã³ã¼ãã¨åç (* tell application "System Events" tell process "Mail" set frontmost to true keystroke "n" using {command down, option down} end tell end tell *)
æåã®ã²ã¨å¼å¸
- åºæ¥ä¸ãã£ã便å©ãªAppleScriptã¯ãèªåã®å ´åãQuicksilverã§ã·ã§ã¼ãã«ãããå²ãå½ã¦ã¦å®è¡ãããã¨ãå¤ãã
- ãã®æã¡ãã£ã¨ããã³ããå¿ è¦ã§ãã¹ã¯ãªãããå®è¡ããæåã®ã¨ããã§ãã²ã¨å¼å¸ããå¿ è¦ãããã®ã ãï¼ç°å¢ã«ãããã0.2ã0.5ç§ãããï¼
- ãã®ã²ã¨å¼å¸ããããªãã¨ããã£ããä½ã£ã便å©ãªã¹ã¯ãªãããæ£å¸¸ã«åä½ããªããã¨ããããï¼çç±ã¯åãããªã...ãï¼
- ãã®ã²ã¨å¼å¸ã click_menu ã shortcut ã«ç¹ã交ãã¦ãã¾ãã¨ãæä½ãã度ã«ã²ã¨å¼å¸ããã¦ãã¾ã£ã¦ãå¦çãé ããªã£ã¦ãã¾ãã
- å¦çã®æåã« delay 0.5 ã¨æ¸ãã¦ãè¯ãã®ã ããQuicksilverã®ã·ã§ã¼ãã«ããããå®è¡ããã¨ãã ãå¿ è¦ãªã®ã§ã以ä¸ã®ããã«ãã¦ã¿ãã
--åæåå¦çï¼Quicksilverããã®èµ·åãªããã²ã¨å¼å¸ç½®ãã¦å®è¡ããï¼ on init() if is_from_quicksilver() then delay 0.2 end if end init --Quicksilverããèµ·åãã¦ãããã©ãã on is_from_quicksilver() try my name as text false on error true end try end is_from_quicksilver
ã©ã¤ãã©ãªã¨ãã¦ä¿åãã¦å©ç¨
- 以ä¸ãåºæ¥ä¸ãã£ãã¹ã¯ãªããã ~/Library/Scripts/_gui.scpt ã¨ãã¦ä¿åããã
- ãã®ã¹ã¯ãªããï¼_gui.scptï¼ã¯ã以ä¸ã®ããã«ãã¦åå©ç¨ãããã¨ãã§ãããï¼åºæ¬ã®2ä¾ãæ¸ãç´ãã¦ã¿ãï¼
(*ãã¡ã¤ã«åï¼spotlight_with_selection.scpt*) property GUI : load script file ((path to scripts folder as text) & "_gui.scpt") --set GUI to load script file ((path to scripts folder as text) & "_keyboard.scpt") GUI's init() --GUI's check() --ãã¼æä½ã®ã¿ã®å ´åã¯ä¸è¦ GUI's shortcut("", "command-c") GUI's shortcut("", "control-space") GUI's shortcut("", "command-V")
- property GUI : load script file...ã¨ãã¦ã¹ã¯ãªãããåãè¾¼ãã°...
- ä¸è¨ã¹ã¯ãªããä¿åæã«ã_gui.scptãã¹ã¯ãªãããªãã¸ã§ã¯ãã¨ãã¦ããããã£å¤æ°GUIã«åãè¾¼ã¾ããåããã¡ã¤ã«ã«ä¿åãããã
- ãã®ç¶æ ã¯ãspotlight_with_selection.scptã«_gui.scptãå«ã¾ãã¦ããã®ã§ã_gui.scptã®åå¨ã«é¢ä¿ãªãå®è¡ã§ããã
- ãã®ãã¨ã¯ã_gui.scptãå¤æ´ãã¦ãããã®å¤æ´ã¯spotlight_with_selection.scptãåä¿åããã¾ã§åæ ãããªããã¨ãæå³ããã
- set GUI to load script file...ã¨ãã¦ã¹ã¯ãªãããåãè¾¼ãã°...
- ä¸è¨ã¹ã¯ãªããå®è¡æã«ã_gui.scptãã¹ã¯ãªãããªãã¸ã§ã¯ãã¨ãã¦ãã¼ã«ã«å¤æ°GUIã«åãè¾¼ã¾ããã
- ãã¼ã«ã«å¤æ°ã¯ä¿æããããå®è¡æã«èªã¿è¾¼ã¾ããã®ã§ã_gui.scptãå®è¡æã«å¿ ãå¿ è¦ã«ãªãã
- _gui.scptãå¤æ´ããã¨ããã®å¤æ´ã¯spotlight_with_selection.scptãå®è¡ããæã«åæ ãããã
(*ãã¡ã¤ã«åï¼mail_encoding_auto.scpt*) property GUI : load script file ((path to scripts folder as text) & "_gui.scpt") on adding folder items to this_folder after receiving added_items tell application "Finder" to open added_items GUI's init() GUI's check() GUI's shortcut("Mail", "command-option-1") GUI's shortcut("", "command-W") GUI's click_menu("", "ã¦ã¤ã³ãã¦/ã¡ãã»ã¼ã¸ãã¥ã¼ã¢") GUI's shortcut("", "command-W") GUI's shortcut("", "command-option-N") end adding folder items to
ããªãã·ã³ãã«ã«æ¸ããããã«ãªã£ãï¼ä¾¿å©ãªã¹ã¯ãªããããã£ã±ãä½ã£ã¦æ¥½ãããï¼
- ã©ã¤ãã©ãªãå«ããã®ã¹ã¯ãªããã®ダウンロードページã¸