Created
March 24, 2019 22:12
-
-
Save yearofthewhopper/d988d66ba9c790705a0683bb6817ca23 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
property open_folder : true | |
property touch_file : false | |
property time_fmt : 1 | |
property bring_to_front : true | |
property organized_folder : "" | |
property ignore_kinds : {"Safari download", "Finder Document"} | |
-- Add suffixes to ignore. don't include the '.' | |
property ignore_suffix : {"nzb", "torent"} | |
property date_fmt : "+%Y-%m-%d" -- | |
(* | |
Best to leave this alone. | |
*) | |
on run | |
display dialog "Wanna show the folder when you're downloading new stuff?" buttons {"Don't Show", "Show"} default button 2 | |
if the button returned of the result is "Don't Show" then | |
set open_folder to false | |
else | |
set open_folder to true | |
end if | |
display dialog "Wanna make the Finder active when new items are added?" buttons {"Don't Activate", "Activate"} default button 2 | |
if the button returned of the result is "Don't Activate" then | |
set bring_to_front to false | |
else | |
set bring_to_front to true | |
end if | |
display dialog "Do ya wanna to set the modification date to the time you downloaded these items?" buttons {"Change Modification Date", "Don't Change Modification Date"} default button 2 | |
if the button returned of the result is "Don't Change Modification Date" then | |
set touch_file to false | |
else | |
set touch_file to true | |
end if | |
end run | |
on open of the_files | |
if (organized_folder is equal to "") then | |
set_organized_folder() | |
end if | |
tell application "Finder" to move the_files to organized_folder | |
end open | |
on set_organized_folder() | |
set organized_folder to (choose folder) | |
end set_organized_folder | |
on getSuffix(myFile) | |
tell application "Finder" to set myFile to name of myFile | |
if myFile contains "." then | |
set oldDelims to AppleScript's text item delimiters | |
set AppleScript's text item delimiters to "." | |
set theSuffix to last text item of myFile | |
set AppleScript's text item delimiters to oldDelims | |
return theSuffix | |
end if | |
end getSuffix | |
on adding folder items to this_folder after receiving added_items | |
set the_path to POSIX path of this_folder | |
set date_cmd to "date '" & date_fmt & "'" | |
set todays_folder to do shell script of date_cmd | |
-- display dialog ((the number of added_items) as string) & " items added" -- | |
repeat with i from 1 to number of items in added_items | |
set this_item to item i of added_items | |
--display dialog the kind of (info for this_item) as string | |
set item_kind to the kind of (info for this_item) as string | |
set item_suffix to getSuffix(this_item as text) | |
if (item_kind is in ignore_kinds) or (item_suffix is in ignore_suffix) then | |
display dialog item_kind & " or " & item_suffix & " is being ignored" | |
else | |
set item_name to the name of (info for this_item) | |
if (item_name is not equal to todays_folder) then | |
-- display dialog "Name: " & item_name | |
set make_folder_cmd to "/bin/test -d " & quoted form of (the_path & todays_folder) & " || /bin/mkdir " & quoted form of (the_path & todays_folder) | |
--display dialog make_folder_cmd | |
do shell script make_folder_cmd | |
set move_file_cmd to "/bin/test -d " & quoted form of (the_path & todays_folder) & " && /bin/mv -n " & quoted form of (the_path & item_name) & " " & quoted form of (the_path & todays_folder) & "/" | |
--display dialog "Running: " & move_file_cmd | |
do shell script move_file_cmd | |
if (touch_file is true) then | |
set touch_file_cmd to "/usr/bin/touch " & quoted form of (the_path & todays_folder & "/" & item_name) | |
--display dialog "Running: " & touch_file_cmd | |
do shell script touch_file_cmd | |
end if | |
else | |
-- display dialog "Dated folder.. not running" | |
end if | |
end if | |
end repeat | |
if (open_folder is true) then | |
if (bring_to_front is true) then | |
tell application "Finder" to activate | |
end if | |
set the_folder to the_path & todays_folder | |
set the_folder to POSIX file the_folder | |
tell application "Finder" to open folder the_folder | |
end if | |
end adding folder items to |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment