hello all,
i’m a first-time poster and new to applescript, so forgive me if this post seems a bit obvious…
i am working on a web-based application, and need to create a script that:
- Takes media files uploaded to a directory and converts them to hinted, self-contained .mov’s
- Saves these files in another directory where they will be available for streaming
I’ve created a script that doesn’t work, but have had trouble debugging it:
on adding folder items to this_folder after receiving these_items
tell application "Finder"
if not (exists folder "Done" of this_folder) then
make new folder at this_folder with properties {name:"Done"}
end if
set the destination_folder to folder "Done" of this_folder as alias
end tell
repeat with i from 1 to number of items in these_items
set this_item to item i of these_items
set the item_info to info for this_item
set file_name to the name of the item_info
if the name extension of item_info is in {"mp3", "wav"} then
tell application "QuickTime Player"
launch
-- THIS IS WHAT DOESNT SEEM TO WORK:
export item_info to (destination_folder & file_name) as "QuickTime hinted movie"
end tell
end if
end repeat
end adding folder items to
Please help if you can!
Thanks,
David
Hi David,
the variable item_info contains a record of some information about the file, not the file itself.
And destination_folder is an alias, but should be a string path.
And hinted movie is a reserved constant, a literal string “QuickTime hinted movie” doesn’t work
try:
.
export this_item to ((destination_folder as text) & file_name) as hinted movie
.
Thanks Stefan-
i’m sure that’s part of the problem. unfortunately, there may be more problems since it still is not exporting a file. How does one check for error messages in applescirpt? i’m not having much luck.
-David
you must test folder actions this way, because you don’t get any error messages in a folder action
-- on adding folder items to this_folder after receiving these_items
set this_folder to choose folder
set these_items to choose file with multiple selections allowed
.
.
-- end adding folder items to
There is another problem in your script: When the folder is created in the hot folder,
the folder action will be called again.
I’ve made this into a non-folder actions script, and am still having problems.
set destination_folder to choose folder
set these_items to choose file with multiple selections allowed
repeat with this_item in these_items
beep 1
set item_info to info for this_item
set file_name to name of item_info
if name extension of item_info is in {"mp3", "wav"} then
tell application "QuickTime Player"
launch
export file_name to ((destination_folder as text) & "new.mov") as "QuickTime hinted movie"
end tell
end if
end repeat
However this creates the error:
QuickTime Player got an error: Can’t get alias “Macintosh HD:Users:alt10hof:Desktop:qt_test:major_funk.mp3”.
…not a very helpful message.
But this is not the main problem.
file_name is just the name of the file, but you
have to export the file, which is this_item.
To export the file it has first to be opened
set destination_folder to choose folder
set these_items to choose file with multiple selections allowed
repeat with this_item in these_items
beep 1
set {name:file_name, name extension:Ext} to info for this_item
if Ext is in {"mp3", "wav"} then
tell application "QuickTime Player"
launch
open this_item
export document 1 to ((destination_folder as text) & "new.mov") as hinted movie
end tell
end if
end repeat
Yeaa! It finally exported. Thanks Stefan!
…on a side note. Doesn’t it seems kind of obtuse to have to do things that way? Why should you have to open a file (and start it playing) in order to export it.
… and how does “this_item” become “document 1”
Well, looks like got some learning to do.
Best,
David
Playing is not the question. But if you’re going to manipulate a file, you have to open it.
You have to do this since the very early days of computing
Immagine to change text in TextEdit without an open file.
if you open a file in QuickTime, it becomes always the frontmost document,
which can be referred easily without knowing the file name as document 1.
Note: for batch processing you should close the frontmost document after exporting it with
close document 1
inside the QuickTime tell block