Created
May 28, 2012 10:34
-
-
Save geeksunny/2818423 to your computer and use it in GitHub Desktop.
A folder-action script to automatically add new files to the iTunes library
This file contains 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
global app_state | |
-- check if itunes is running | |
set app_state to false | |
tell application "System Events" | |
if (exists process "iTunes") then set app_state to true | |
end tell | |
-- Adding files to the iTunes library when they are added to the watched folder | |
on adding folder items to my_folder after receiving the_files | |
repeat with i from 1 to number of items in the_files | |
tell application "iTunes" | |
if app_state is false then | |
launch | |
end if | |
try | |
set this_file to (item i of the_files) | |
add this_file | |
end try | |
end tell | |
--DEBUG | |
--set this_file to (item i of the_files) | |
--display alert this_file as text | |
end repeat | |
end adding folder items to | |
-- Removing files from the library when they get removed from the directory | |
(* | |
-- Just doesn't work right now... | |
on removing folder items from my_folder after losing the_files | |
--delay 3 | |
repeat with i from 1 to number of items in the_files | |
--display alert "REMOVING" --DEBUG | |
tell application "iTunes" | |
if app_state is false then | |
launch | |
end if | |
try | |
set this_file to (item i of the_files) | |
display alert this_file as text | |
tell this_file | |
set track_name to get name | |
end tell | |
delete track_name | |
display alert track_name as text | |
on error errmesg number errn | |
display dialog errmesg & return & return & "error number: " & (errn as text) | |
end try | |
end tell | |
--DEBUG | |
--set this_file to (item i of the_files) | |
--display alert this_file as text | |
end repeat | |
end removing folder items from | |
*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment