Skip to content

Instantly share code, notes, and snippets.

@n8henrie
Last active May 15, 2020 16:40
Show Gist options
  • Save n8henrie/4e06cdaba21341e5ad93 to your computer and use it in GitHub Desktop.
Save n8henrie/4e06cdaba21341e5ad93 to your computer and use it in GitHub Desktop.
Template for Folder Actions to allow easy interactive testing in Script Editor, should work seamlessly once activated as Folder Actions.
-- http://n8henrie.com/2016/02/template-for-more-efficient-applescript-folder-actions/
property test_folder : "/path/to/action/folder"
property test_file : "/path/to/action/folder/file.txt"
on main(this_folder, these_items)
tell application "Finder"
-- Uncomment below 2 lines to run on *every* file in the folder when this script runs
-- set list_of_files to every item in this_folder
-- repeat with this_file in list_of_files
-- Uncomment below line to run on only the newly added files
repeat with this_file in these_items
-- Example action to take, replace with whatever you want to do
tell application "System Events" to set creationDate to creation date of this_file
if creationDate is less than ((current date) - (4 * weeks)) then
display notification (name of this_file & " was created on " & creationDate)
-- move this_file to trash
end if
end repeat
end tell
end main
-- Test files to be run interactively in Script Editor.app
on run
set _test_folder to (POSIX file test_folder) as alias
set _test_file to (POSIX file test_file) as alias
set _test_items to {_test_file}
main(_test_folder, _test_items)
end run
-- This portion should function identically when called as a Folder Action
on adding folder items to this_folder after receiving these_items
main(this_folder, these_items)
end adding folder items to
@ravemir
Copy link

ravemir commented May 6, 2020

I hate to be that guy to simply add a thanks message, but this saved the few hairs I have left in me, by allowing me to test my folder action script 😌

@n8henrie
Copy link
Author

n8henrie commented May 15, 2020 via email

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