Skip to content

Instantly share code, notes, and snippets.

@koinzhang
Last active July 9, 2025 12:39
Show Gist options
  • Select an option

  • Save koinzhang/a4ab45b6f71fcab0ce0f15cd370184b0 to your computer and use it in GitHub Desktop.

Select an option

Save koinzhang/a4ab45b6f71fcab0ce0f15cd370184b0 to your computer and use it in GitHub Desktop.
Simple AppleScript
-- Show system hidden files
tell application "Finder" to quit
tell application "System Events" to do shell script "defaults write com.apple.finder AppleShowAllFiles -bool true"
tell application "Finder" to launch
-- copy file to clipboard
tell app "Finder" to set the clipboard to (POSIX file "/Users/zhangyongkang/Desktop/Markdown.md")
-- Hide the window of visible applications
tell application "System Events"
set visibleApps to every process whose visible is true
repeat with theApp in visibleApps
set visible of theApp to false
end repeat
end tell
-- get insertion location of Finder
tell application "Finder"
set folderPath to insertion location as alias
set fileName to ("filename with extension")
if exists file (folderPath & fileName as text) then
return true
else
return false
end if
end tell
-- get active application
tell application "System Events"
set activeApp to name of current application
end tell
-- get location of application
tell application "System Events"
tell process "Finder"
set _location to position of back window
end tell
end tell
-- get size of application
tell application "System Events"
tell process "Finder"
set _size to size of front window
end tell
end tell
-- get finder window directory path
tell application "Finder"
set windowList to windows
set finderWindowPath to {}
repeat with _window in windowList
set the end of finderWindowPath to POSIX path of (folder of _window as alias)
end repeat
return finderWindowPath
end tell
-- is application running
if application "Finder" is not running then
return "Not running"
end if
-- is application minimized
tell application "Finder"
set windowList to windows
set allCollapse to true
repeat with _window in windowList
set allCollapse to (collapsed of (_window)) and allCollapse
end repeat
return allCollapse
end tell
-- is application has windows
if windows of application "Finder" is {} then
return false
else
return true
end if
-- is Path valid
set filePath to ("${folderPath}")
try
POSIX file filePath as alias
return true
on error
return false
end try
-- create new tab in Opera browser
on run argv
try
activate application "Opera"
on error
tell application "Opera"
activate
delay 1
if windows of application "Opera" is {} then
tell application "Opera" to key code 45 using {command down}
else
tell front window
make new tab with properties {URL:"https://www.zhihu.com"}
end tell
end if
end tell
end try
end run
-- simulate key press
tell application "System Events"
key code 40 using {command down}
end tell
-- More key tips https://eastmanreference.com/complete-list-of-applescript-key-codes
-- quit all app except for Finder app
tell application "System Events" to set quitapps to name of every application process whose visible is true and name is not "Finder"
repeat with closeall in quitapps
quit application closeall
end repeat
-- Quick Look
tell application "Finder"
set pathFile to POSIX file "/Users/zhangyongkang/Desktop/Code"
set pathFile to get POSIX path of pathFile
do shell script "qlmanage -p \"" & pathFile & "\""
end tell
-- open link in clipboard
set link to the clipboard
open location link
-- support for:
-- raycast://confetti
-- mailto:[email protected]
-- https://www.raycast.com
-- no support for:
-- www.raycast.com
-- raycast.com
-- /Users/zhangyongkang/Desktop
-- ~/Desktop
-- choose file or folder, return path
return POSIX path of (choose folder)
return POSIX path of (choose file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment