Differences
This shows you the differences between two versions of the page.
— | devwiki:applescript [2021/08/28 07:48] (current) – created ying | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== AppleScript tips ====== | ||
+ | * application automation <code applescript> | ||
+ | * computer operation <code applescript> | ||
+ | property target_URL : " | ||
+ | open location target_URL | ||
+ | </ | ||
+ | * system operation <code applescript> | ||
+ | set volume 7 | ||
+ | beep 5 | ||
+ | say " | ||
+ | say " | ||
+ | </ | ||
+ | * user interaction <code applescript> | ||
+ | display dialog "How are you today?" | ||
+ | buttons {" | ||
+ | default button " | ||
+ | with icon 1 [with icon note] | ||
+ | giving up after 5 | ||
+ | delay 60 -- //delay 60 seconds | ||
+ | display dialog " | ||
+ | default answer " | ||
+ | </ | ||
+ | * user input automation <code applescript> | ||
+ | tell application " | ||
+ | tell process (path to frontmost application as string) | ||
+ | keystroke " | ||
+ | end tell | ||
+ | end tell | ||
+ | </ | ||
+ | * script and shell automation <code applescript> | ||
+ | do shell script "cd ~/ | ||
+ | </ | ||
+ | * path convertion <code applescript> | ||
+ | -- unix path to applescript path | ||
+ | set applePath to POSIX file "/ | ||
+ | set applePath to POSIX file mySel as Unicode text | ||
+ | -- apple path to unix path | ||
+ | set bashPath to POSIX path of applePath | ||
+ | </ | ||
+ | * pipe data from command by bracket <code applescript> | ||
+ | * text processing | ||
+ | |||
+ | ====== system preference ====== | ||
+ | * change dock size <code applescript> | ||
+ | set dockPrefs to (path to preferences folder from user domain as text) & " | ||
+ | |||
+ | -- get the current location of the dock and use that to toggle your settings | ||
+ | tell application " | ||
+ | tell property list file dockPrefs to set theLocation to value of property list item " | ||
+ | |||
+ | -- set the dock size: a value between 0 and 1 | ||
+ | tell dock preferences | ||
+ | if theLocation is " | ||
+ | set dock size to 0.1 | ||
+ | else | ||
+ | set dock size to 0.9 | ||
+ | end if | ||
+ | end tell | ||
+ | |||
+ | -- set the position: left, right, or bottom | ||
+ | tell property list file dockPrefs | ||
+ | if theLocation is " | ||
+ | set value of property list item " | ||
+ | else | ||
+ | set value of property list item " | ||
+ | end if | ||
+ | end tell | ||
+ | end tell | ||
+ | |||
+ | -- quit and relaunch the dock with the new settings | ||
+ | tell application " | ||
+ | </ | ||
+ | * toggle keyboard function key <code applescript> | ||
+ | tell application " | ||
+ | activate | ||
+ | set current pane to pane " | ||
+ | end tell | ||
+ | |||
+ | tell application " | ||
+ | -- If we don't have UI Elements enabled, then nothing is really going to work. | ||
+ | if UI elements enabled then | ||
+ | tell application process " | ||
+ | get properties | ||
+ | |||
+ | click radio button " | ||
+ | click checkbox "Use all F1, F2, etc. keys as standard function keys" of tab group 1 of window " | ||
+ | end tell | ||
+ | tell application " | ||
+ | else | ||
+ | -- GUI scripting not enabled. | ||
+ | tell application " | ||
+ | activate | ||
+ | set current pane to pane " | ||
+ | display dialog "UI element scripting is not enabled. Please activate \" | ||
+ | end tell | ||
+ | end if | ||
+ | end tell | ||
+ | </ | ||
+ | ====== Keycode of AppleScript ====== | ||
+ | |||
+ | ^ esc | 53 ^ tab | 48 ^ ' | ||
+ | ^ F1 | 122 ^ ` | 50 ^ , | ||
+ | ^ F2 | 120 ^ 1 | 18 ^ . | 14 ^ e | 2 ^ j | 8 | | ||
+ | ^ F3 | 99 ^ 2 | 19 ^ p | 15 ^ u | 3 ^ k | 9 | | ||
+ | ^ F4 | 118 ^ 3 | 20 ^ y | 17 ^ i | 5 ^ x | 11 | | ||
+ | ^ F5 | 96 ^ 4 | 21 ^ f | 16 ^ d | 4 ^ b | 45 | | ||
+ | ^ F6 | 97 ^ 5 | 23 ^ g | 32 ^ h | 38 ^ m | 46 | | ||
+ | ^ F7 | 98 ^ 6 | 22 ^ c | 34 ^ t | 40 ^ w | 43 | | ||
+ | ^ F8 | 100 ^ 7 | 26 ^ r | 31 ^ n | 37 ^ v | 47 | | ||
+ | ^ F9 | 101 ^ 8 | 28 ^ l | 35 ^ s | 41 ^ z | 44 | | ||
+ | ^ F10 | 109 ^ 9 | 25 ^ / | ||
+ | ^ F11 | 103 ^ 0 | 29 ^ = | 30 ^ return | 36 ^ up | 126 | | ||
+ | ^ F12 | ? | ||
+ | ^ delete | 51 ^ ] | 24 ^ | ^ enter | 52 ^ right | 124 | | ||
+ | |||
+ | ====== AppleScript ready-to-use library ====== | ||
+ | * http:// |