├── Contacts.applescript ├── Copy File Path.workflow └── Contents │ ├── Info.plist │ ├── QuickLook │ └── Thumbnail.png │ └── document.wflow ├── Create Clean Archive.workflow └── Contents │ ├── Info.plist │ ├── QuickLook │ └── Preview.png │ └── document.wflow ├── Import to Photos.applescript ├── Makefile ├── Merge.applescript ├── Move Window Down.applescript ├── Move Window Up.applescript.applescript ├── Move Window to Center.applescript ├── Move Window to Left.applescript ├── Move Window to Right.applescript ├── Open In Sublime.workflow └── Contents │ ├── Info.plist │ ├── QuickLook │ └── Thumbnail.png │ └── document.wflow ├── Open in Terminal.applescript ├── Open in iTerm2.applescript ├── Show Hidden Files.applescript ├── Skim New From Clipboard.applescript └── Typora Align Environment.applescript /Contacts.applescript: -------------------------------------------------------------------------------- 1 | on sed(srcString, pattern) 2 | do shell script "echo " & quoted form of srcString & " |" & "sed '" & pattern & "'" 3 | end sed 4 | 5 | tell application "Contacts" 6 | set chg to "Yes" 7 | set formatfb to button returned of (display dialog ("Remove Social Profiles?") as string buttons {"Yes", "No"} default button 2 with title "Confirm") 8 | set formatpn to button returned of (display dialog ("Format Phone number?" & return & "This can be slow") as string buttons {"Yes", "No"} default button 2 with title "Confirm") 9 | 10 | if formatfb is "Yes" or formatpn is "Yes" then 11 | repeat with thePerson in people 12 | 13 | set icloud to false 14 | repeat with g in (name of groups of thePerson as list) 15 | if g contains "card" then 16 | set icloud to true 17 | exit repeat 18 | end if 19 | end repeat 20 | if icloud is false then 21 | 22 | # reformat contact info 23 | if formatfb is "Yes" then 24 | if not company of thePerson then 25 | delete organization of thePerson 26 | delete job title of thePerson 27 | end if 28 | delete url of thePerson 29 | delete birth date of thePerson 30 | delete (user name of every social profile of thePerson) 31 | set (service name of every social profile of thePerson) to "" 32 | set url of every social profile of thePerson to "" 33 | delete address of thePerson 34 | --delete image of thePerson 35 | end if 36 | 37 | -- format phone number 38 | if formatpn is "Yes" then 39 | repeat with thePhone in phone of thePerson 40 | set phonenum to ((value of thePhone) as string) 41 | 42 | # reformat the number 43 | set phonenum to my sed(phonenum, "s/[ ()\\-]//g") 44 | 45 | # add area code 46 | if character 1 of phonenum is not "+" then 47 | set areacode to "" 48 | if length of phonenum is 8 then 49 | set areacode to "+852" 50 | else if length of phonenum is 10 then 51 | set areacode to "+1" 52 | else if length of phonenum is 11 then 53 | set areacode to "+86" 54 | end if 55 | if areacode is not "" then 56 | if chg is not "Yes to all" then 57 | set personinfo to "Name: " & first name of thePerson & " " & last name of thePerson 58 | if organization of thePerson is not missing value then 59 | set personinfo to personinfo & newLine & "Company: " & organization of thePerson 60 | end if 61 | set personinfo to personinfo & return & areacode & " " & phonenum & "?" 62 | set chg to button returned of (display dialog {personinfo} as string buttons {"Yes", "Yes to all", "No"} default button 3 with title "Change the following number?") 63 | if chg is not "No" then set phonenum to areacode & phonenum 64 | else 65 | set phonenum to areacode & phonenum 66 | end if 67 | end if 68 | end if 69 | 70 | set value of thePhone to phonenum 71 | end repeat 72 | end if 73 | end if 74 | end repeat 75 | end if 76 | display dialog "Finish" 77 | save 78 | end tell -------------------------------------------------------------------------------- /Copy File Path.workflow/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSServices 6 | 7 | 8 | NSMenuItem 9 | 10 | default 11 | Copy File Path 12 | 13 | NSMessage 14 | runWorkflowAsService 15 | NSSendFileTypes 16 | 17 | public.item 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Copy File Path.workflow/Contents/QuickLook/Thumbnail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/randy3k/osascript/877358cdd463ceaabbbc20f73170ff6c9a71f3a3/Copy File Path.workflow/Contents/QuickLook/Thumbnail.png -------------------------------------------------------------------------------- /Copy File Path.workflow/Contents/document.wflow: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AMApplicationBuild 6 | 346 7 | AMApplicationVersion 8 | 2.3 9 | AMDocumentVersion 10 | 2 11 | actions 12 | 13 | 14 | action 15 | 16 | AMAccepts 17 | 18 | Container 19 | List 20 | Optional 21 | 22 | Types 23 | 24 | com.apple.cocoa.string 25 | com.apple.cocoa.attributed-string 26 | 27 | 28 | AMActionVersion 29 | 1.2.1 30 | AMApplication 31 | 32 | System 33 | 34 | AMParameterProperties 35 | 36 | AMProvides 37 | 38 | Container 39 | List 40 | Optional 41 | 42 | Types 43 | 44 | com.apple.cocoa.string 45 | com.apple.cocoa.attributed-string 46 | 47 | 48 | ActionBundlePath 49 | /System/Library/Automator/Copy to Clipboard.action 50 | ActionName 51 | Copy to Clipboard 52 | ActionParameters 53 | 54 | BundleIdentifier 55 | com.apple.Automator.CopyToClipboard 56 | CFBundleVersion 57 | 1.2.1 58 | CanShowSelectedItemsWhenRun 59 | 60 | CanShowWhenRun 61 | 62 | Category 63 | 64 | AMCategoryUtilities 65 | 66 | Class Name 67 | AMCopyToClipboardAction 68 | InputUUID 69 | CFAE93AA-E8F9-4C01-975D-1E312FDA71B8 70 | Keywords 71 | 72 | Copy 73 | 74 | OutputUUID 75 | E8874193-AB27-47B6-B0F9-C9D2973137BD 76 | UUID 77 | 1CDE918D-2407-429A-B293-D48949FF70D2 78 | UnlocalizedApplications 79 | 80 | System 81 | 82 | arguments 83 | 84 | conversionLabel 85 | 0 86 | 87 | 88 | 89 | connectors 90 | 91 | workflowMetaData 92 | 93 | serviceInputTypeIdentifier 94 | com.apple.Automator.fileSystemObject 95 | serviceOutputTypeIdentifier 96 | com.apple.Automator.nothing 97 | serviceProcessesInput 98 | 0 99 | workflowTypeIdentifier 100 | com.apple.Automator.servicesMenu 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /Create Clean Archive.workflow/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSServices 6 | 7 | 8 | NSMenuItem 9 | 10 | default 11 | Create Clean Archive 12 | 13 | NSMessage 14 | runWorkflowAsService 15 | NSSendFileTypes 16 | 17 | public.item 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Create Clean Archive.workflow/Contents/QuickLook/Preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/randy3k/osascript/877358cdd463ceaabbbc20f73170ff6c9a71f3a3/Create Clean Archive.workflow/Contents/QuickLook/Preview.png -------------------------------------------------------------------------------- /Create Clean Archive.workflow/Contents/document.wflow: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AMApplicationBuild 6 | 428 7 | AMApplicationVersion 8 | 2.7 9 | AMDocumentVersion 10 | 2 11 | actions 12 | 13 | 14 | action 15 | 16 | AMAccepts 17 | 18 | Container 19 | List 20 | Optional 21 | 22 | Types 23 | 24 | com.apple.cocoa.path 25 | 26 | 27 | AMActionVersion 28 | 1.1.2 29 | AMApplication 30 | 31 | Finder 32 | 33 | AMParameterProperties 34 | 35 | fileNames 36 | 37 | 38 | AMProvides 39 | 40 | Container 41 | List 42 | Types 43 | 44 | com.apple.cocoa.path 45 | 46 | 47 | ActionBundlePath 48 | /System/Library/Automator/Get Specified Finder Items.action 49 | ActionName 50 | Get Specified Finder Items 51 | ActionParameters 52 | 53 | fileNames 54 | 55 | 56 | BundleIdentifier 57 | com.apple.Automator.SpecifiedFiles 58 | CFBundleVersion 59 | 1.1.2 60 | CanShowSelectedItemsWhenRun 61 | 62 | CanShowWhenRun 63 | 64 | Category 65 | 66 | AMCategoryFilesAndFolders 67 | 68 | Class Name 69 | SpecifiedFilesAction 70 | InputUUID 71 | 47381384-E722-484D-8A61-F5C4A906853F 72 | Keywords 73 | 74 | File 75 | Choose 76 | Find 77 | Get 78 | 79 | OutputUUID 80 | C58C855D-E01D-41F3-A41A-1138130C4C3D 81 | UUID 82 | CE819B70-AC32-4813-A333-FD78F5F67106 83 | UnlocalizedApplications 84 | 85 | Finder 86 | 87 | arguments 88 | 89 | 0 90 | 91 | default value 92 | 93 | name 94 | fileNames 95 | required 96 | 0 97 | type 98 | 0 99 | uuid 100 | 0 101 | 102 | 103 | conversionLabel 104 | 0 105 | isViewVisible 106 | 107 | location 108 | 321.000000:308.000000 109 | nibPath 110 | /System/Library/Automator/Get Specified Finder Items.action/Contents/Resources/Base.lproj/main.nib 111 | 112 | isViewVisible 113 | 114 | 115 | 116 | action 117 | 118 | AMAccepts 119 | 120 | Container 121 | List 122 | Optional 123 | 124 | Types 125 | 126 | com.apple.cocoa.string 127 | 128 | 129 | AMActionVersion 130 | 2.0.3 131 | AMApplication 132 | 133 | Automator 134 | 135 | AMParameterProperties 136 | 137 | COMMAND_STRING 138 | 139 | CheckedForUserDefaultShell 140 | 141 | inputMethod 142 | 143 | shell 144 | 145 | source 146 | 147 | 148 | AMProvides 149 | 150 | Container 151 | List 152 | Types 153 | 154 | com.apple.cocoa.string 155 | 156 | 157 | ActionBundlePath 158 | /System/Library/Automator/Run Shell Script.action 159 | ActionName 160 | Run Shell Script 161 | ActionParameters 162 | 163 | COMMAND_STRING 164 | declare -a names 165 | declare -a parts 166 | declare i=0 167 | 168 | names=("$@") 169 | name="$1" 170 | while x=$(dirname "$name"); [ "$x" != "/" ] 171 | do 172 | parts[$i]="$x" 173 | i=$(($i + 1)) 174 | name="$x" 175 | done 176 | 177 | for prefix in "${parts[@]}" / 178 | do 179 | for name in "${names[@]}" 180 | do 181 | if [ "${name#$prefix/}" = "${name}" ] 182 | then continue 2 183 | fi 184 | done 185 | dir="$prefix" 186 | break 187 | done 188 | 189 | cd "$dir" 190 | 191 | for file in "${names[@]}" 192 | do 193 | zip zip-file.zip -r "${file#$dir/}" -x *.DS_Store 194 | done 195 | CheckedForUserDefaultShell 196 | 197 | inputMethod 198 | 0 199 | shell 200 | /bin/bash 201 | source 202 | 203 | 204 | BundleIdentifier 205 | com.apple.RunShellScript 206 | CFBundleVersion 207 | 2.0.3 208 | CanShowSelectedItemsWhenRun 209 | 210 | CanShowWhenRun 211 | 212 | Category 213 | 214 | AMCategoryUtilities 215 | 216 | Class Name 217 | RunShellScriptAction 218 | InputUUID 219 | DCE1C7AB-01F3-4138-84D2-0FE218E32811 220 | Keywords 221 | 222 | Shell 223 | Script 224 | Command 225 | Run 226 | Unix 227 | 228 | OutputUUID 229 | BCD5AD19-35C6-413E-9A35-7CFFCE5368AF 230 | UUID 231 | C4881C60-4005-48C4-8FDC-71CA7F0921D2 232 | UnlocalizedApplications 233 | 234 | Automator 235 | 236 | arguments 237 | 238 | 0 239 | 240 | default value 241 | 0 242 | name 243 | inputMethod 244 | required 245 | 0 246 | type 247 | 0 248 | uuid 249 | 0 250 | 251 | 1 252 | 253 | default value 254 | 255 | name 256 | source 257 | required 258 | 0 259 | type 260 | 0 261 | uuid 262 | 1 263 | 264 | 2 265 | 266 | default value 267 | 268 | name 269 | CheckedForUserDefaultShell 270 | required 271 | 0 272 | type 273 | 0 274 | uuid 275 | 2 276 | 277 | 3 278 | 279 | default value 280 | 281 | name 282 | COMMAND_STRING 283 | required 284 | 0 285 | type 286 | 0 287 | uuid 288 | 3 289 | 290 | 4 291 | 292 | default value 293 | /bin/sh 294 | name 295 | shell 296 | required 297 | 0 298 | type 299 | 0 300 | uuid 301 | 4 302 | 303 | 304 | conversionLabel 305 | 0 306 | isViewVisible 307 | 308 | location 309 | 321.000000:491.000000 310 | nibPath 311 | /System/Library/Automator/Run Shell Script.action/Contents/Resources/English.lproj/main.nib 312 | 313 | isViewVisible 314 | 315 | 316 | 317 | connectors 318 | 319 | 2B3EFEE4-617C-4713-9D69-173AC1120C22 320 | 321 | from 322 | CE819B70-AC32-4813-A333-FD78F5F67106 - CE819B70-AC32-4813-A333-FD78F5F67106 323 | to 324 | C4881C60-4005-48C4-8FDC-71CA7F0921D2 - C4881C60-4005-48C4-8FDC-71CA7F0921D2 325 | 326 | 327 | state 328 | 329 | AMLogTabViewSelectedIndex 330 | 0 331 | libraryState 332 | 333 | actionsMajorSplitViewState 334 | 335 | expandedPosition 336 | 0.0 337 | subviewState 338 | 339 | 0.000000, 0.000000, 381.000000, 515.000000, NO 340 | 0.000000, 516.000000, 381.000000, 223.000000, NO 341 | 342 | 343 | actionsMinorSplitViewState 344 | 345 | expandedPosition 346 | 0.0 347 | subviewState 348 | 349 | 0.000000, 0.000000, 163.000000, 515.000000, NO 350 | 164.000000, 0.000000, 217.000000, 515.000000, NO 351 | 352 | 353 | variablesMajorSplitViewState 354 | 355 | expandedPosition 356 | 0.0 357 | subviewState 358 | 359 | 0.000000, 0.000000, 350.000000, 555.000000, NO 360 | 0.000000, 556.000000, 350.000000, 148.000000, NO 361 | 362 | 363 | variablesMinorSplitViewState 364 | 365 | expandedPosition 366 | 0.0 367 | subviewState 368 | 369 | 0.000000, 0.000000, 163.000000, 555.000000, NO 370 | 164.000000, 0.000000, 186.000000, 555.000000, NO 371 | 372 | 373 | 374 | majorSplitViewState 375 | 376 | expandedPosition 377 | 0.0 378 | subviewState 379 | 380 | 0.000000, 0.000000, 381.000000, 784.000000, NO 381 | 382.000000, 0.000000, 619.000000, 784.000000, NO 382 | 383 | 384 | minorSplitViewState 385 | 386 | expandedPosition 387 | 162 388 | subviewState 389 | 390 | 0.000000, 0.000000, 619.000000, 593.000000, NO 391 | 0.000000, 603.000000, 619.000000, 162.000000, NO 392 | 393 | 394 | windowFrame 395 | {{302, 255}, {1000, 861}} 396 | workflowViewScrollPosition 397 | {{0, 0}, {619, 593}} 398 | 399 | workflowMetaData 400 | 401 | serviceInputTypeIdentifier 402 | com.apple.Automator.fileSystemObject 403 | serviceOutputTypeIdentifier 404 | com.apple.Automator.nothing 405 | serviceProcessesInput 406 | 0 407 | workflowTypeIdentifier 408 | com.apple.Automator.servicesMenu 409 | 410 | 411 | 412 | -------------------------------------------------------------------------------- /Import to Photos.applescript: -------------------------------------------------------------------------------- 1 | tell application "Finder" 2 | activate 3 | choose folder with prompt "Please choose a folder to import into Photos as an album:" 4 | set theFolderToImport to the result 5 | set theFoldersName to the name of theFolderToImport 6 | set thePhotosToImport to the files of theFolderToImport 7 | set thePhotosToImportAsAliases to {} 8 | repeat with b in thePhotosToImport 9 | set a to b as alias 10 | set the end of thePhotosToImportAsAliases to a 11 | end repeat 12 | end tell 13 | 14 | tell application "Photos" 15 | activate 16 | delay 2 17 | set theNewAlbum to make new album named theFoldersName 18 | --import thePhotosToImportAsAliases into theNewAlbum with skip check duplicates 19 | import thePhotosToImportAsAliases into theNewAlbum 20 | end tell -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | git add -A \ 3 | && git commit -m "Update osascript at $$(date)" \ 4 | && git push 5 | -------------------------------------------------------------------------------- /Merge.applescript: -------------------------------------------------------------------------------- 1 | on gui_scripting_status() 2 | tell application "System Events" 3 | set ui_enabled to UI elements enabled 4 | end tell 5 | if ui_enabled is false then 6 | tell application "System Preferences" 7 | activate 8 | set current pane to pane id "com.apple.preference.universalaccess" 9 | display dialog "The GUI scripting architecture of Mac OS X is currently disabled." & return & return & "To activate GUI Scripting select the checkbox \"Enable access for assistive devices\" in the Universal Access preference pane." with icon 1 buttons {"Okay"} default button 1 10 | end tell 11 | end if 12 | return ui_enabled 13 | end gui_scripting_status 14 | 15 | on click_menu(app_name, menu_name, menu_item) 16 | try 17 | tell application app_name 18 | activate 19 | end tell 20 | tell application "System Events" 21 | click menu item menu_item of menu menu_name of menu bar 1 of process app_name 22 | end tell 23 | return true 24 | on error error_message 25 | return false 26 | end try 27 | end click_menu 28 | 29 | on frontApp() 30 | tell application "System Events" 31 | name of first process whose frontmost is true 32 | end tell 33 | end frontApp 34 | 35 | set thefrontApp to frontApp() 36 | 37 | if gui_scripting_status() then 38 | click_menu(thefrontApp, "Window", "Merge All Windows") 39 | end if -------------------------------------------------------------------------------- /Move Window Down.applescript: -------------------------------------------------------------------------------- 1 | use framework "AppKit" 2 | use scripting additions 3 | 4 | on getMainScreen() 5 | set nss to current application's NSScreen 6 | repeat with sc in nss's screens() 7 | set f to sc's frame() 8 | if item 1 of item 1 of f is 0 and item 2 of item 1 of f is 0 then 9 | return f 10 | end if 11 | end repeat 12 | return 0 13 | end getMainScreen 14 | 15 | set actualScreen to current application's NSScreen's mainScreen's frame() 16 | set actualWidth to item 1 of item 2 of actualScreen 17 | set actualHeight to item 2 of item 2 of actualScreen 18 | set visibleScreen to current application's NSScreen's mainScreen's visibleFrame() 19 | set screenWidth to item 1 of item 2 of visibleScreen 20 | set screenHeight to item 2 of item 2 of visibleScreen 21 | set originX to item 1 of item 1 of visibleScreen 22 | set originY to ((item 2 of item 2 of my getMainScreen()) - (item 2 of item 1 of visibleScreen) - screenHeight) 23 | 24 | 25 | on approx(a, b) 26 | set ret to ((a - b) ^ 2) ^ 0.5 27 | return ret is less than or equal to 10 28 | end approx 29 | 30 | on match(windowWidth, windowHeight, w, h) 31 | set ret to ((windowWidth - (my screenWidth) * w) ^ 2 + (windowHeight - (my screenHeight) * h) ^ 2) ^ 0.5 32 | return ret is less than or equal to 25 33 | end match 34 | 35 | tell application "System Events" to tell (process 1 where frontmost is true) 36 | set windowResolution to size of the first window 37 | set windowPos to position of the first window 38 | set windowWidth to item 1 of windowResolution 39 | set windowHeight to item 2 of windowResolution 40 | set windowX to item 1 of windowPos 41 | set windowY to item 2 of windowPos 42 | 43 | if my approx(windowX, originX) and windowWidth < screenWidth * 0.65 then 44 | if windowHeight < screenHeight * 0.55 and windowY > originY + screenHeight / 2 then 45 | set the position of the first window to {originX, originY} 46 | set the size of the first window to {windowWidth, screenHeight} 47 | else 48 | set the size of the first window to {windowWidth, screenHeight / 2} 49 | set the position of the first window to {originX, originY + screenHeight / 2} 50 | end if 51 | return 52 | end if 53 | 54 | if my approx(windowX + windowWidth, originX + screenWidth) and windowWidth < screenWidth * 0.65 then 55 | if windowHeight < screenHeight * 0.55 and windowY > originY + screenHeight / 2 then 56 | set the position of the first window to {windowX, originY} 57 | set the size of the first window to {windowWidth, screenHeight} 58 | else 59 | set the position of the first window to {windowX, originY + screenHeight / 2} 60 | set the size of the first window to {windowWidth, screenHeight / 2} 61 | end if 62 | return 63 | end if 64 | 65 | if my match(windowWidth, windowHeight, 0.7, 0.8) then 66 | set windowWidth to screenWidth * 0.55 67 | set windowHeight to screenHeight * 0.65 68 | set midX to originX + screenWidth * 0.5 + (random number from -50 to 50) 69 | set midY to originY + screenHeight * 0.5 + (random number from -50 to 50) 70 | else if my match(windowWidth, windowHeight, 0.55, 0.65) then 71 | set windowWidth to screenWidth * 0.4 72 | set windowHeight to screenHeight * 0.5 73 | set midX to originX + screenWidth * 0.5 + (random number from -50 to 50) 74 | set midY to originY + screenHeight * 0.5 + (random number from -50 to 50) 75 | else if my match(windowWidth, windowHeight, 0.4, 0.5) then 76 | set windowWidth to screenWidth 77 | set windowHeight to screenHeight 78 | set midX to originX + screenWidth * 0.5 79 | set midY to originY + screenHeight * 0.5 80 | else 81 | set windowWidth to screenWidth * 0.7 82 | set windowHeight to screenHeight * 0.8 83 | set midX to originX + screenWidth * 0.5 + (random number from -50 to 50) 84 | set midY to originY + screenHeight * 0.5 + (random number from -50 to 50) 85 | end if 86 | set the position of the first window to {midX - windowWidth / 2, midY - windowHeight / 2} 87 | set the size of the first window to {windowWidth, windowHeight} 88 | end tell 89 | -------------------------------------------------------------------------------- /Move Window Up.applescript.applescript: -------------------------------------------------------------------------------- 1 | use framework "AppKit" 2 | use scripting additions 3 | 4 | on getMainScreen() 5 | set nss to current application's NSScreen 6 | repeat with sc in nss's screens() 7 | set f to sc's frame() 8 | if item 1 of item 1 of f is 0 and item 2 of item 1 of f is 0 then 9 | return f 10 | end if 11 | end repeat 12 | return 0 13 | end getMainScreen 14 | 15 | set actualScreen to current application's NSScreen's mainScreen's frame() 16 | set actualWidth to item 1 of item 2 of actualScreen 17 | set actualHeight to item 2 of item 2 of actualScreen 18 | set visibleScreen to current application's NSScreen's mainScreen's visibleFrame() 19 | set screenWidth to item 1 of item 2 of visibleScreen 20 | set screenHeight to item 2 of item 2 of visibleScreen 21 | set originX to item 1 of item 1 of visibleScreen 22 | set originY to ((item 2 of item 2 of my getMainScreen()) - (item 2 of item 1 of visibleScreen) - screenHeight) 23 | 24 | 25 | on approx(a, b) 26 | set ret to ((a - b) ^ 2) ^ 0.5 27 | return ret is less than or equal to 10 28 | end approx 29 | 30 | on match(windowWidth, windowHeight, w, h) 31 | set ret to ((windowWidth - (my screenWidth) * w) ^ 2 + (windowHeight - (my screenHeight) * h) ^ 2) ^ 0.5 32 | return ret is less than or equal to 25 33 | end match 34 | 35 | tell application "System Events" to tell (process 1 where frontmost is true) 36 | set windowResolution to size of the first window 37 | set windowPos to position of the first window 38 | set windowWidth to item 1 of windowResolution 39 | set windowHeight to item 2 of windowResolution 40 | set windowX to item 1 of windowPos 41 | set windowY to item 2 of windowPos 42 | 43 | if my approx(windowX, originX) and windowWidth < screenWidth * 0.65 then 44 | if windowHeight > screenHeight * 0.55 then 45 | set the size of the first window to {windowWidth, screenHeight / 2} 46 | else 47 | set the size of the first window to {windowWidth, screenHeight} 48 | end if 49 | set the position of the first window to {originX, originY} 50 | return 51 | end if 52 | 53 | if my approx(windowX + windowWidth, originX + screenWidth) and windowWidth < screenWidth * 0.65 then 54 | if windowHeight > screenHeight * 0.55 then 55 | set the size of the first window to {windowWidth, screenHeight / 2} 56 | else 57 | set the size of the first window to {windowWidth, screenHeight} 58 | end if 59 | set the position of the first window to {windowX, originY} 60 | return 61 | end if 62 | 63 | if my match(windowWidth, windowHeight, 1, 1) then 64 | set windowWidth to screenWidth * 0.4 65 | set windowHeight to screenHeight * 0.5 66 | set midX to originX + screenWidth * 0.5 + (random number from -50 to 50) 67 | set midY to originY + screenHeight * 0.5 + (random number from -50 to 50) 68 | else if my match(windowWidth, windowHeight, 0.4, 0.5) then 69 | set windowWidth to screenWidth * 0.55 70 | set windowHeight to screenHeight * 0.65 71 | set midX to originX + screenWidth * 0.5 + (random number from -50 to 50) 72 | set midY to originY + screenHeight * 0.5 + (random number from -50 to 50) 73 | else if my match(windowWidth, windowHeight, 0.55, 0.65) then 74 | set windowWidth to screenWidth * 0.7 75 | set windowHeight to screenHeight * 0.8 76 | set midX to originX + screenWidth * 0.5 + (random number from -50 to 50) 77 | set midY to originY + screenHeight * 0.5 + (random number from -50 to 50) 78 | else 79 | set windowWidth to screenWidth 80 | set windowHeight to screenHeight 81 | set midX to originX + screenWidth * 0.5 82 | set midY to originY + screenHeight * 0.5 83 | end if 84 | set the position of the first window to {midX - windowWidth / 2, midY - windowHeight / 2} 85 | set the size of the first window to {windowWidth, windowHeight} 86 | end tell 87 | -------------------------------------------------------------------------------- /Move Window to Center.applescript: -------------------------------------------------------------------------------- 1 | use framework "AppKit" 2 | use scripting additions 3 | 4 | on getMainScreen() 5 | set nss to current application's NSScreen 6 | repeat with sc in nss's screens() 7 | set f to sc's frame() 8 | if item 1 of item 1 of f is 0 and item 2 of item 1 of f is 0 then 9 | return f 10 | end if 11 | end repeat 12 | return 0 13 | end getMainScreen 14 | 15 | set actualScreen to current application's NSScreen's mainScreen's frame() 16 | set actualWidth to item 1 of item 2 of actualScreen 17 | set actualHeight to item 2 of item 2 of actualScreen 18 | set visibleScreen to current application's NSScreen's mainScreen's visibleFrame() 19 | set screenWidth to item 1 of item 2 of visibleScreen 20 | set screenHeight to item 2 of item 2 of visibleScreen 21 | set originX to item 1 of item 1 of visibleScreen 22 | set originY to ((item 2 of item 2 of my getMainScreen()) - (item 2 of item 1 of visibleScreen) - screenHeight) 23 | 24 | 25 | tell application "System Events" to tell (process 1 where frontmost is true) 26 | set windowResolution to size of the first window 27 | set windowWidth to item 1 of windowResolution 28 | set windowHeight to item 2 of windowResolution 29 | 30 | set windowWidth to screenWidth * 0.55 31 | set windowHeight to screenHeight * 0.65 32 | set midX to originX + screenWidth * 0.5 + (random number from -50 to 50) 33 | set midY to originY + screenHeight * 0.5 + (random number from -50 to 50) 34 | 35 | set the position of the first window to {midX - windowWidth / 2, midY - windowHeight / 2} 36 | set the size of the first window to {windowWidth, windowHeight} 37 | end tell 38 | -------------------------------------------------------------------------------- /Move Window to Left.applescript: -------------------------------------------------------------------------------- 1 | use framework "AppKit" 2 | use scripting additions 3 | 4 | on getMainScreen() 5 | set nss to current application's NSScreen 6 | repeat with sc in nss's screens() 7 | set f to sc's frame() 8 | if item 1 of item 1 of f is 0 and item 2 of item 1 of f is 0 then 9 | return f 10 | end if 11 | end repeat 12 | return 0 13 | end getMainScreen 14 | 15 | set actualScreen to current application's NSScreen's mainScreen's frame() 16 | set actualWidth to item 1 of item 2 of actualScreen 17 | set actualHeight to item 2 of item 2 of actualScreen 18 | set visibleScreen to current application's NSScreen's mainScreen's visibleFrame() 19 | set screenWidth to item 1 of item 2 of visibleScreen 20 | set screenHeight to item 2 of item 2 of visibleScreen 21 | set originX to item 1 of item 1 of visibleScreen 22 | set originY to ((item 2 of item 2 of my getMainScreen()) - (item 2 of item 1 of visibleScreen) - screenHeight) 23 | 24 | 25 | on approx(a, b) 26 | set ret to ((a - b) ^ 2) ^ 0.5 27 | return ret is less than or equal to 10 28 | end approx 29 | 30 | tell application "System Events" to tell (process 1 where frontmost is true) 31 | set windowResolution to size of the first window 32 | set windowPos to position of the first window 33 | set windowWidth to item 1 of windowResolution 34 | set windowHeight to item 2 of windowResolution 35 | set windowX to item 1 of windowPos 36 | set windowY to item 2 of windowPos 37 | 38 | if my approx(windowX + windowWidth, originX + screenWidth) then 39 | tell application "Finder" to set thefolder to (container of (path to me)) as text 40 | run script (thefolder & "Move Window to Center.applescript") as alias 41 | 42 | else if my approx(windowWidth, 0.6 * screenWidth) and windowX is equal to originX then 43 | set the size of the first window to {screenWidth * 0.5, windowHeight} 44 | set the position of the first window to {originX, windowY} 45 | 46 | else if my approx(windowWidth, 0.5 * screenWidth) and windowX is equal to originX then 47 | set the size of the first window to {screenWidth * 0.4, windowHeight} 48 | set the position of the first window to {originX, windowY} 49 | 50 | else if my approx(windowWidth, 0.4 * screenWidth) and windowX is equal to originX then 51 | set the position of the first window to {originX, windowY} 52 | set the size of the first window to {screenWidth * 0.6, windowHeight} 53 | 54 | else 55 | set the size of the first window to {screenWidth * 0.6, screenHeight} 56 | set the position of the first window to {originX, originY} 57 | -- since the size may not be corrent for some position, do sizing again 58 | set the size of the first window to {screenWidth * 0.6, screenHeight} 59 | 60 | end if 61 | end tell 62 | -------------------------------------------------------------------------------- /Move Window to Right.applescript: -------------------------------------------------------------------------------- 1 | use framework "AppKit" 2 | use scripting additions 3 | 4 | on getMainScreen() 5 | set nss to current application's NSScreen 6 | repeat with sc in nss's screens() 7 | set f to sc's frame() 8 | if item 1 of item 1 of f is 0 and item 2 of item 1 of f is 0 then 9 | return f 10 | end if 11 | end repeat 12 | return 0 13 | end getMainScreen 14 | 15 | set actualScreen to current application's NSScreen's mainScreen's frame() 16 | set actualWidth to item 1 of item 2 of actualScreen 17 | set actualHeight to item 2 of item 2 of actualScreen 18 | set visibleScreen to current application's NSScreen's mainScreen's visibleFrame() 19 | set screenWidth to item 1 of item 2 of visibleScreen 20 | set screenHeight to item 2 of item 2 of visibleScreen 21 | set originX to item 1 of item 1 of visibleScreen 22 | set originY to ((item 2 of item 2 of my getMainScreen()) - (item 2 of item 1 of visibleScreen) - screenHeight) 23 | 24 | 25 | on approx(a, b) 26 | set ret to ((a - b) ^ 2) ^ 0.5 27 | return ret is less than or equal to 10 28 | end approx 29 | 30 | tell application "System Events" to tell (process 1 where frontmost is true) 31 | set windowResolution to size of the first window 32 | set windowPos to position of the first window 33 | set windowWidth to item 1 of windowResolution 34 | set windowHeight to item 2 of windowResolution 35 | set windowX to item 1 of windowPos 36 | set windowY to item 2 of windowPos 37 | 38 | if my approx(windowX, originX) then 39 | tell application "Finder" to set thefolder to (container of (path to me)) as text 40 | run script (thefolder & "Move Window to Center.applescript") as alias 41 | 42 | else if my approx(windowWidth, 0.6 * screenWidth) and my approx(windowX + windowWidth, originX + screenWidth) then 43 | set the size of the first window to {screenWidth * 0.5, windowHeight} 44 | set the position of the first window to {originX + screenWidth * 0.5 + 1, windowY} 45 | 46 | else if my approx(windowWidth, 0.4 * screenWidth) and my approx(windowX + windowWidth, originX + screenWidth) then 47 | set the size of the first window to {screenWidth * 0.6, windowHeight} 48 | set the position of the first window to {originX + screenWidth * 0.4 + 1, windowY} 49 | -- since the size may not be correct for some position, do sizing again 50 | set the size of the first window to {screenWidth * 0.6, windowHeight} 51 | 52 | else if my approx(windowWidth, 0.5 * screenWidth) and my approx(windowX + windowWidth, originX + screenWidth) then 53 | set the size of the first window to {screenWidth * 0.4, windowHeight} 54 | set the position of the first window to {originX + screenWidth * 0.6 + 1, windowY} 55 | -- since the size may not be correct for some position, do sizing again 56 | set the size of the first window to {screenWidth * 0.4, windowHeight} 57 | 58 | else 59 | set the size of the first window to {screenWidth * 0.4, screenHeight} 60 | set the position of the first window to {originX + screenWidth * 0.6 + 1, originY} 61 | -- since the size may not be correct for some position, do sizing again 62 | set the size of the first window to {screenWidth * 0.4, screenHeight} 63 | end if 64 | end tell 65 | -------------------------------------------------------------------------------- /Open In Sublime.workflow/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSServices 6 | 7 | 8 | NSMenuItem 9 | 10 | default 11 | Open In Sublime 12 | 13 | NSMessage 14 | runWorkflowAsService 15 | NSSendFileTypes 16 | 17 | public.item 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Open In Sublime.workflow/Contents/QuickLook/Thumbnail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/randy3k/osascript/877358cdd463ceaabbbc20f73170ff6c9a71f3a3/Open In Sublime.workflow/Contents/QuickLook/Thumbnail.png -------------------------------------------------------------------------------- /Open In Sublime.workflow/Contents/document.wflow: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AMApplicationBuild 6 | 417 7 | AMApplicationVersion 8 | 2.6 9 | AMDocumentVersion 10 | 2 11 | actions 12 | 13 | 14 | action 15 | 16 | AMAccepts 17 | 18 | Container 19 | List 20 | Optional 21 | 22 | Types 23 | 24 | com.apple.cocoa.string 25 | 26 | 27 | AMActionVersion 28 | 2.0.3 29 | AMApplication 30 | 31 | Automator 32 | 33 | AMParameterProperties 34 | 35 | COMMAND_STRING 36 | 37 | CheckedForUserDefaultShell 38 | 39 | inputMethod 40 | 41 | shell 42 | 43 | source 44 | 45 | 46 | AMProvides 47 | 48 | Container 49 | List 50 | Types 51 | 52 | com.apple.cocoa.string 53 | 54 | 55 | ActionBundlePath 56 | /System/Library/Automator/Run Shell Script.action 57 | ActionName 58 | Run Shell Script 59 | ActionParameters 60 | 61 | COMMAND_STRING 62 | subl -a $@ 63 | CheckedForUserDefaultShell 64 | 65 | inputMethod 66 | 1 67 | shell 68 | /bin/bash 69 | source 70 | 71 | 72 | BundleIdentifier 73 | com.apple.RunShellScript 74 | CFBundleVersion 75 | 2.0.3 76 | CanShowSelectedItemsWhenRun 77 | 78 | CanShowWhenRun 79 | 80 | Category 81 | 82 | AMCategoryUtilities 83 | 84 | Class Name 85 | RunShellScriptAction 86 | InputUUID 87 | 08A491F0-4D9C-49CC-BA7B-E2780D18F060 88 | Keywords 89 | 90 | Shell 91 | Script 92 | Command 93 | Run 94 | Unix 95 | 96 | OutputUUID 97 | FD65C2CA-F5BF-46A6-8F34-DEF4A082D9AB 98 | UUID 99 | BA5B7074-A861-4B23-882A-942CDA166728 100 | UnlocalizedApplications 101 | 102 | Automator 103 | 104 | arguments 105 | 106 | 0 107 | 108 | default value 109 | 0 110 | name 111 | inputMethod 112 | required 113 | 0 114 | type 115 | 0 116 | uuid 117 | 0 118 | 119 | 1 120 | 121 | default value 122 | 123 | name 124 | source 125 | required 126 | 0 127 | type 128 | 0 129 | uuid 130 | 1 131 | 132 | 2 133 | 134 | default value 135 | 136 | name 137 | CheckedForUserDefaultShell 138 | required 139 | 0 140 | type 141 | 0 142 | uuid 143 | 2 144 | 145 | 3 146 | 147 | default value 148 | 149 | name 150 | COMMAND_STRING 151 | required 152 | 0 153 | type 154 | 0 155 | uuid 156 | 3 157 | 158 | 4 159 | 160 | default value 161 | /bin/sh 162 | name 163 | shell 164 | required 165 | 0 166 | type 167 | 0 168 | uuid 169 | 4 170 | 171 | 172 | isViewVisible 173 | 174 | location 175 | 309.000000:253.000000 176 | nibPath 177 | /System/Library/Automator/Run Shell Script.action/Contents/Resources/English.lproj/main.nib 178 | 179 | isViewVisible 180 | 181 | 182 | 183 | connectors 184 | 185 | workflowMetaData 186 | 187 | serviceInputTypeIdentifier 188 | com.apple.Automator.fileSystemObject 189 | serviceOutputTypeIdentifier 190 | com.apple.Automator.nothing 191 | serviceProcessesInput 192 | 0 193 | workflowTypeIdentifier 194 | com.apple.Automator.servicesMenu 195 | 196 | 197 | 198 | -------------------------------------------------------------------------------- /Open in Terminal.applescript: -------------------------------------------------------------------------------- 1 | on appIsRunning(appName) 2 | tell application "System Events" to (name of processes) contains appName 3 | end appIsRunning 4 | 5 | on sed(srcString, pattern) 6 | do shell script "echo " & quoted form of srcString & " |" & "sed '" & pattern & "'" 7 | end sed 8 | 9 | on urldecode(URLpath) 10 | set URLpath to do shell script "x=" & quoted form of URLpath & ";x=${x/#file:\\/\\/};x=${x/#localhost}; printf ${x//%/\\\\x}" 11 | return URLpath 12 | end urldecode 13 | 14 | on frontWinDoc(theApp) 15 | tell application "System Events" to tell process theApp 16 | set URLpath to value of attribute "AXDocument" of window 1 17 | return my urldecode(URLpath) 18 | end tell 19 | end frontWinDoc 20 | 21 | on isDirectory(itemPath) 22 | set fileType to (do shell script "file -b " & quoted form of itemPath) 23 | if fileType ends with "directory" then return true 24 | return false 25 | end isDirectory 26 | 27 | on frontApp() 28 | tell application "System Events" 29 | name of first process whose frontmost is true 30 | end tell 31 | end frontApp 32 | 33 | set thefrontApp to frontApp() 34 | 35 | if thefrontApp is "Finder" then 36 | tell application "Finder" 37 | try 38 | set thefolder to (insertion location) as alias 39 | set thefolder to (POSIX path of thefolder) 40 | on error 41 | set thefolder to do shell script "echo ~/" 42 | end try 43 | end tell 44 | else if thefrontApp is "iTerm2" and appIsRunning("Sublime Text") then 45 | tell application "Sublime Text" to activate 46 | else 47 | try 48 | set thefrontWinDoc to frontWinDoc(thefrontApp) 49 | if thefrontWinDoc is not "missing value" then 50 | if my isDirectory(thefrontWinDoc) then 51 | set thefolder to thefrontWinDoc 52 | else 53 | set thefolder to (do shell script "dirname " & quoted form of thefrontWinDoc) & "/" 54 | end if 55 | else 56 | set thefolder to do shell script "echo ~/" 57 | end if 58 | on error 59 | set thefolder to do shell script "echo ~/" 60 | end try 61 | end if 62 | 63 | set thefolder to (do shell script "cd " & quoted form of thefolder & "; pwd -P") & "/" 64 | set detected to false 65 | --display dialog thefolder 66 | 67 | if my appIsRunning("Terminal") then 68 | tell application "System Events" to tell process "Terminal" 69 | repeat with w in windows 70 | try 71 | set thetitle to name of w 72 | set termfolder to my urldecode(value of attribute "AXDocument" of w) 73 | if termfolder is thefolder and (thetitle contains "bash" or thetitle contains "zsh") then 74 | set detected to true 75 | perform action "AXRaise" of w 76 | exit repeat 77 | end if 78 | end try 79 | end repeat 80 | end tell 81 | end if 82 | 83 | if not detected then 84 | do shell script "open -a terminal " & quoted form of thefolder 85 | end if 86 | -------------------------------------------------------------------------------- /Open in iTerm2.applescript: -------------------------------------------------------------------------------- 1 | -- required iTerm 3.1 2 | 3 | on appIsRunning(appName) 4 | tell application "System Events" to (name of processes) contains appName 5 | end appIsRunning 6 | 7 | on sed(srcString, pattern) 8 | do shell script "echo " & quoted form of srcString & " |" & "sed '" & pattern & "'" 9 | end sed 10 | 11 | on urldecode(URLpath) 12 | set URLpath to do shell script "x=" & quoted form of URLpath & ";x=${x/#file:\\/\\/};x=${x/#localhost}; printf ${x//%/\\\\x}" 13 | return URLpath 14 | end urldecode 15 | 16 | on frontWinDoc(theApp) 17 | tell application "System Events" to tell process theApp 18 | set URLpath to value of attribute "AXDocument" of window 1 19 | return my urldecode(URLpath) 20 | end tell 21 | end frontWinDoc 22 | 23 | on isDirectory(itemPath) 24 | set fileType to (do shell script "file -b " & quoted form of itemPath) 25 | if fileType ends with "directory" then return true 26 | return false 27 | end isDirectory 28 | 29 | on frontApp() 30 | tell application "System Events" 31 | name of first process whose frontmost is true 32 | end tell 33 | end frontApp 34 | 35 | set thefrontApp to frontApp() 36 | 37 | if thefrontApp is "Finder" then 38 | tell application "Finder" 39 | try 40 | set thefolder to (insertion location) as alias 41 | set thefolder to (POSIX path of thefolder) 42 | on error 43 | set thefolder to do shell script "echo ~/" 44 | end try 45 | end tell 46 | -- else if thefrontApp is "iTerm2" and appIsRunning("Sublime Text") then 47 | -- tell application "Sublime Text" to activate 48 | else 49 | try 50 | set thefrontWinDoc to frontWinDoc(thefrontApp) 51 | if thefrontWinDoc is not "missing value" then 52 | if my isDirectory(thefrontWinDoc) then 53 | set thefolder to thefrontWinDoc 54 | else 55 | set thefolder to (do shell script "dirname " & quoted form of thefrontWinDoc) & "/" 56 | end if 57 | else 58 | set thefolder to do shell script "echo ~/" 59 | end if 60 | on error 61 | set thefolder to do shell script "echo ~/" 62 | end try 63 | end if 64 | 65 | set thefolder to (do shell script "cd " & quoted form of thefolder & "; pwd -P") & "/" 66 | set detected to false 67 | --display dialog thefolder 68 | 69 | on pwd_tty(tty_name) 70 | -- Based on http://genbastechthoughts.wordpress.com/2012/07/10/how-to-duplicate-an-iterm-tab-using-applescript/ 71 | set pid to do shell script ("ps -f | grep " & tty_name & " | grep 'zsh\\|bash' | head -n 1 | awk '{ print $2; }'") 72 | set ret to do shell script ("lsof -a -d cwd -F n -p " & pid & " | grep ^n | awk '{ sub(/^n/, \"\"); print; }'") 73 | return ret 74 | end pwd_tty 75 | 76 | if my appIsRunning("iTerm2") then 77 | tell application "iTerm" 78 | repeat with w in windows 79 | if (count of (tabs of w)) is 0 then 80 | exit repeat 81 | end if 82 | set s to w's current tab's current session 83 | set thetitle to get name of s 84 | set tty_name to do shell script "basename " & (get tty of s) 85 | set working_dir to my pwd_tty(tty_name) 86 | if working_dir & "/" is thefolder and (thetitle contains "bash" or thetitle contains "zsh") then 87 | set detected to true 88 | exit repeat 89 | end if 90 | end repeat 91 | end tell 92 | end if 93 | 94 | if detected then 95 | tell application "System Events" 96 | tell process "iTerm2" 97 | set frontmost to true 98 | perform action "AXRaise" of (first window whose title is thetitle) 99 | end tell 100 | end tell 101 | tell application "iTerm" to activate 102 | else 103 | tell application "iTerm" 104 | open thefolder 105 | activate 106 | end tell 107 | end if 108 | -------------------------------------------------------------------------------- /Show Hidden Files.applescript: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/randy3k/osascript/877358cdd463ceaabbbc20f73170ff6c9a71f3a3/Show Hidden Files.applescript -------------------------------------------------------------------------------- /Skim New From Clipboard.applescript: -------------------------------------------------------------------------------- 1 | tell application "System Events" to tell process "Skim" 2 | set frontmost to true 3 | tell menu bar item "File" of menu bar 1 4 | click 5 | click menu item "New From Clipboard" of menu 1 6 | end tell 7 | end tell -------------------------------------------------------------------------------- /Typora Align Environment.applescript: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/randy3k/osascript/877358cdd463ceaabbbc20f73170ff6c9a71f3a3/Typora Align Environment.applescript --------------------------------------------------------------------------------