Projects: AppleScript
AppleScript
OmniOutliner
Arrange Windows: this script sets the 2 front OO windows as wide as the screen and over and under/horizontally. Requires Jon’s Commands.
Arrange Columns: this script sets columns 2 & 3 to the same width which is roughly half of the window width minus the other two columns. (Column one is for checkboxen or some such.)
Folder Actions
add-archive: this makes a zip archive (inside the target folder) of anything placed in that target folder. It tests for various bogosities, such as a zip or an alias, and creates Mac compatible archives. To use it, put the script in Library/Scripts/Folder Action Scripts (either at the root or in your Home folder).
Open this script in your script editor
on adding folder items to thisFolder after receiving addedItems
tell application "Finder"
set folderPath to POSIX path of thisFolder
end tell
--make a time stamp for a unique dir name
tell (current date)
set theMonth to addLeadingZeros((its month as number), 1) of me
set theDay to addLeadingZeros((its day as number), 1) of me
set dateValue to (year as string) & theMonth & theDay
set timeValue to its time
set timeStamp to dateValue & timeValue
end tell
--because multiple items require an extra step
if (count of addedItems) is 1 then
set theItem to (item 1 of addedItems)
set toArchive to checkFile(theItem)
if toArchive is not false then
--trim needed so ditto can properly handle directories
set toArchive to (trimLineEnd(toArchive, "/"))
set archiveName to toArchive & ".zip"
--make sure there's not already an archive there with that name
--should only occur if it's a single file or folder being archived
--if so, gin up a unique name using time stamp
tell application "System Events" to set targetCheck to exists archiveName
if targetCheck then
set archiveName to toArchive & timeStamp & ".zip"
end if
set toArchive to quoted form of toArchive
processItem(toArchive, archiveName)
end if
else --to handle multiple files
--we need to copy the files to a temporary location
--and archive THAT directory instead
set copyFiles to ""
--make the temp dir
set tmpDir to ("/tmp/" & timeStamp)
do shell script "mkdir " & quoted form of (tmpDir)
--loop through the files
repeat with thisItem in addedItems
set toCopy to (checkFile(thisItem))
if toCopy is not false then
--to preserve the directory structure
if folder of (info for (thisItem)) then
set dstDir to tmpDir & "/" & name of (info for (thisItem))
else
set dstDir to tmpDir
end if
set dstDir to quoted form of dstDir
set toCopy to quoted form of toCopy
end if
--copy the file
set copyCommand to "usr/bin/ditto --rsrc " & toCopy & " " & dstDir
do shell script copyCommand
end repeat
set toArchive to tmpDir
set archiveName to quoted form of (folderPath & "Archive " & timeStamp & ".zip")
--make the archive
processItem(toArchive, archiveName)
end if
end adding folder items to
--this sub-routine creates the archive
on processItem(theFile, theArchive)
set theCommand to "usr/bin/ditto -c -k -rsrc --keepParent" & " " & theFile & " " & theArchive
do shell script theCommand
end processItem
--we don't want to process zips and aliases
on checkFile(theFile)
if (theFile as text) ends with ".zip" then
return false
end if
if alias of (info for theFile) is true then
return false
end if
return (POSIX path of file (theFile as text))
end checkFile
on addLeadingZeros(thisNumber, maxLeadingZeros)
set the thresholdNumber to (10 ^ maxLeadingZeros) as integer
if thisNumber is less than the thresholdNumber then
set the leadingZeros to ""
set the digitCount to the length of ((thisNumber div 1) as string)
set the characterCount to (maxLeadingZeros + 1) - digitCount
repeat characterCount times
set the leadingZeros to (the leadingZeros & "0") as string
end repeat
return (leadingZeros & (thisNumber as text)) as string
else
return thisNumber as text
end if
end addLeadingZeros
on trimLineEnd(thisText, trimChars) --modified from a subroutines on the AppleScript site
set x to the length of the trimChars
repeat while thisText ends with the trimChars
try
set thisText to characters 1 thru -(x + 1) of thisText as string
on error
--the text contains nothing but the trim characters
return ""
end try
end repeat
return thisText
end trimLineEnd

