Skip to content

Instantly share code, notes, and snippets.

@JordanReiter
Created November 16, 2012 16:10
Show Gist options
  • Save JordanReiter/4088570 to your computer and use it in GitHub Desktop.
Save JordanReiter/4088570 to your computer and use it in GitHub Desktop.
AppleScript file -- create scratch file in TextWrangler
property file_formats : {¬
"cfm", ¬
"html", ¬
"js", ¬
"py", ¬
"sh", ¬
"txt"}
property scratch_folder : "Macintosh HD:path:to:scratch:folder:" as alias
set gg to {year, month, day, hours, minutes, seconds} of (current date)
set yyyy to (item 1 of gg) as string
set mm to item 2 of gg as number
set dd to item 3 of gg
set hh to item 4 of gg
set nn to item 5 of gg
set ss to item 6 of gg
if mm < 10 then
mm = "0" & (mm as string)
end if
if dd < 10 then
dd = "0" & (dd as string)
end if
set datefolder to (yyyy as string) & (mm as string) & (dd as string)
tell application "Finder"
try
make new folder at scratch_folder with properties {name:datefolder}
end try
set today_folder to ((scratch_folder & datefolder) as string) as alias
end tell
tell application "TextWrangler"
activate
make new text document
set filetype to choose from list file_formats with prompt "File type" default items "py"
set filename to "scratch_" & (hh as string) & (nn as string) & (ss as string) & "." & filetype
save text document 1 to file ((today_folder & filename) as string) without saving as stationery
end tell
@JordanReiter
Copy link
Author

I use TextWrangler as my scratch app -- for diffing documents, doing search & replace, or writing up code to paste into a shell. However, at the end of the day I was having dozens of open windows that I had to sift through. Now, this script lets me create a scratch file saved into a scratch directory, so when I'm done I can just choose "Save all" and then "Close All" to close up my scratch files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment