Skip to content

Instantly share code, notes, and snippets.

@dreness
Created April 16, 2024 06:56
Show Gist options
  • Select an option

  • Save dreness/1d6f536b7b9c5628431324a9725c7b47 to your computer and use it in GitHub Desktop.

Select an option

Save dreness/1d6f536b7b9c5628431324a9725c7b47 to your computer and use it in GitHub Desktop.

Revisions

  1. dreness created this gist Apr 16, 2024.
    27 changes: 27 additions & 0 deletions empty-file-in-front-finder-window.scpt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    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