Skip to content

Instantly share code, notes, and snippets.

@dreness
Created April 16, 2024 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dreness/1d6f536b7b9c5628431324a9725c7b47 to your computer and use it in GitHub Desktop.
Save dreness/1d6f536b7b9c5628431324a9725c7b47 to your computer and use it in GitHub Desktop.
Make a new empty file in the front finder window
use scripting additions
use framework "Foundation"
tell application "Finder"
-- path to frontmost Finder window
set windowPath to POSIX path of (target of front window as alias)
-- selected items in Finder, if any
set itemlist to selection as alias list
if length of itemlist > 0 then
repeat with i from 1 to length of itemlist
set the_item to item i of itemlist
set the_result to POSIX path of the_item
return {windowPath, the_result}
end repeat
else
-- there are no selected items in the frontmost Finder window.
set d to seconds of (current date) as string
set cocoaDate to current application's NSDate's dateWithTimeInterval:0 sinceDate:(current date)
set theSeconds to cocoaDate's timeIntervalSince1970()
-- silly hack to get out of scientific notation.
-- Almost any intermediate unit will suffice.
set epochSeconds to theSeconds as ounces as string
set newFile to windowPath & epochSeconds & ".txt"
do shell script "touch " & newFile
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment