Hi everybody,
I am completly new to applescript. Because I need a watchfolder that can automatically convert wave to flac files (audio format) and standard tools didn’t do the trick I decided to dive into the world of Applescript.
Up till now I have puzzled together a script that can convert a wave file to flac and when done it adds in the spotlight comment “opened” the second script moves the flac file to a different location. to automate it I use the lingon tool to tell launchd to watch the wave directory. when there is change is in the wave dir it will start the script. (found the tutorial on http://www.youtube.com/watch?v=1diirrvJR6I)
Uptill now i can only convert files in the top of the wave dierctory not into sub directories.
This is the situation:
In the wave directory automatically comes a new sub directory named beatles and into that subdirectory come the directory “sergeant pepper” and white album.
wave/beatles/sergeant pepper/track_a.wac etc.
wave/beatles/white album/track1.wav etc.
This is what I would like to have:
Launchd is able to see a directory change ( i assume also in a subdirectory), so when the script starts to run it encounters a file without the spotlight comment “opened” , notates what the directory structure is and checks if the output directory already exists, if not then the script should create it. that means that only for the first track from the beatles release the script creates the directory beatles/sergeant pepper into the flac output directory.
The names of the artist and albums are not known in advance. when that’s done the flac files should be renderd into that directory (flac/beatles/sergeant pepper/track_a.flac)
this is what I have done uptill now.
property folder_path : "/Users/eddee/Desktop/wav/"
on run
tell application "Finder"
set action_folder to ((POSIX file folder_path) as alias)
set folder_items to every item in action_folder
end tell
repeat with an_item in folder_items
tell application "Finder"
set item_name to name of (an_item as alias)
set the_comment to (get comment of (an_item as alias))
end tell
if the_comment does not contain "opened" then
set an_item to (an_item as alias)
set input2 to item_name
set input to folder_path
set input3 to "/Users/eddee/Desktop/flac/"
set input4 to item_name
if item_name ends with ".wav" then
do shell script "/opt/local/bin/flac -f -s " & input & "" & input2 & ""
do shell script "osascript /Library/flac/copyanddelete.scpt"
end if
tell application "Finder" to set comment of an_item to (the_comment & " opened")
end if
end repeat
and the copy and delete script I didn’t manage to get the flac encoder point to a new directory, so a move and clean afterwards.
property folder_path : "/Users/eddee/Desktop/wav/"
on run
tell application "Finder"
set action_folder to ((POSIX file folder_path) as alias)
set folder_items to every item in action_folder
end tell
repeat with an_item in folder_items
tell application "Finder"
set item_name to name of (an_item as alias)
set the_comment to (get comment of (an_item as alias))
end tell
set an_item to (an_item as alias)
if item_name ends with ".flac" then
set input to folder_path
set input3 to "/Users/eddee/Desktop/flac/"
set input4 to item_name
do shell script "cp " & input & "" & input4 & " " & input3 & "" & input4 & ""
do shell script "rm -f " & input & "" & input4 & ""
end if
end repeat
and this is launchd xml setup
<?xml version="1.0" encoding="UTF-8"?> Disabled Label com.janpaul.epmflacconvert.folder ProgramArguments /Library/flac/wavnaarflac.app RunAtLoad ServiceDescription watch folder convert wav files to flac WatchPaths /Users/eddee/Desktop/wavO, one more thing, I decided to read a book on applescript (AppleScript The Comprehensive Guide to Scripting and Automation on Mac OS X). After a few tutorials I got stuck the example script does not want to run on my computer (powerbook g4 10.5.8 dutch language) nor on a dualcore 10.5.8 system (english language). The message given is in dutch and tells something like finder cannot get directory applications. Is it me, the system or the book?
tell application "Finder"
tell folder "AppleScript" of folder "Applications"
set file_list to name of every item
set time_folder_was_created to creation date
set time_folder_was_modified to modification date
end tell
end tell
Thanks for your time and I hope that you can give me some hints.
Jan-Paul
Model: powerbook g4
AppleScript: 2.1.2
Browser: Firefox 3.6
Operating System: Mac OS X (10.5)