Item 2. Get each group of sequences in the folder and make into a quicktime mov
The script I have currently allows me to drop a the folder on the applet and then creates a movie with the first set of images. How do I get it to continue to the next set of images?
on open collection
tell application "Finder" to set theSequence to first item of folder collection as alias
tell application "QuickTime Player 7"
activate
open image sequence theSequence frames per second 30
set nameSequence to (theSequence as string) & ".mov"
tell document 1
with timeout of 500 seconds
save self contained in nameSequence
end timeout
end tell
end tell
end open
– note: assumes all sequences begin with “0001” in filenames
on run
set fd to choose folder -- full directory path, is an alias
set flist to list folder fd without invisibles -- list of file names
open {fd, flist}
end run
on open {fd, flist}
repeat with aFile in flist
if ("0001" is in (aFile as text)) then -- this is the first file in a sequence; disregard other files
--make a full path
set fp to ((fd as text) & (aFile as text))
tell application "QuickTime Player 7"
activate
open image sequence fp frames per second 30
set newFP to (fp as text) & ".mov"
tell document 1
with timeout of 100000 seconds
save self contained in newFP
end timeout
end tell
end tell
end if
end repeat
end open
I’ve changed the script a bit so that it creates a folder and then moves the “.mov” files into it. It works with small file sequences but when the file count gets large (500+ files) the app times out. I added the timeout code to the script and it doesn’t time out now but I get the never ending pinwheel.
Not sure why moving files would take so long. Any idea why it’s so processor intensive? Am I doing something wrong in the script? I’ve tried deleting all files that are not “.mov” instead of moving the “.mov” files but have the same problem.
Here’s my script:
on open collection
set myFolder to collection
set fList to list folder myFolder without invisibles
tell application "Finder"
make new folder at (collection as alias) with properties {name:"_MOV"}
end tell
repeat with aFile in fList
if ("0001" is in (aFile as text)) then
set fPath to ((myFolder as text) & (aFile as text))
tell application "QuickTime Player 7"
activate
open image sequence fPath frames per second 30
set fPath to (fPath as text)
set fPath to text 1 thru ((length of fPath) - 4) of fPath
set newPath to (fPath) & ".mov"
tell document 1
with timeout of 10000 seconds
save self contained in newPath
end timeout
end tell
end tell
end if
end repeat
-- Delete all files with same rootname
tell application "Finder"
with timeout of 10000 seconds
set fileExt to {"mov"}
move ((every file of folder (collection as alias)) whose name extension is in fileExt) to the folder "_MOV" of folder collection
end timeout
end tell
end open
I dropped the instruction using list folder which is deprecated for years.
I no longer speak to Finder which is a snail.
I replaced the old fashioned slowwwwww code by a modern one requiring Yosemite or El Capitan.
You will see that I made other changes.
on open collection
set myFolder to collection as text # Define it as text only once. You were doing it at every step of the loop
--set fList to list folder myFolder without invisibles # Deprecated function
tell application "System Events"
set fList to name of files of folder myFolder whose visible is true # the official syntax
set targetFolder to (make new folder at folder myFolder with properties {name:"_MOV"})
end tell
set targetFolder to POSIX path of targetFolder
repeat with aFile in fList
if ("0001" is in aFile) then
set fPath to myFolder & aFile # myFolder is a text object so there is no need to coerce the result as text
tell application "QuickTime Player 7"
activate
open image sequence fPath frames per second 30
--set fPath to (fPath as text) # fPath is already a text object
--set fPath to text 1 thru ((length of fPath) - 4) of fPath
--set fPath to text 1 thru -5 of fPath
--set newPath to fPath & ".mov" # I left the step which braught me to the final syntax
set newPath to text 1 thru -5 of fPath & ".mov"
tell document 1
with timeout of 10000 seconds
save self contained in newPath
end timeout
end tell
end tell
end if
end repeat
# The code below is borrowed to Shane STANLEY
set collection to myFolder as alias # Starting from El Capitan ASObjC may build URLs from an alias
considering numeric strings
if AppleScript's version < "2.5" then set collection to current application's class "NSURL"'s fileURLWithPath:(POSIX path of collection)
end considering
# Build an array of files (in fact URLs) whose extension is "mov"
set fileManager to current application's NSFileManager's defaultManager()
set theURLs to fileManager's contentsOfDirectoryAtURL:collection includingPropertiesForKeys:{} options:(current application's NSDirectoryEnumerationSkipsHiddenFiles) |error|:(missing value)
set extensionList to {"mov"}
set thePredicate to current application's NSPredicate's predicateWithFormat:"(pathExtension IN [c]%@)" argumentArray:{extensionList}
set theURLs to theURLs's filteredArrayUsingPredicate:thePredicate
# Here targetFolder is already a PoSIX File, no need to convert it to this structure
set theDestURL to current application's class "NSURL"'s fileURLWithPath:targetFolder --(POSIX path of targetFolder)
# Move the identified files to the target one
repeat with oneURL in theURLs
set theName to oneURL's lastPathComponent()
(fileManager's moveItemAtURL:oneURL toURL:(theDestURL's URLByAppendingPathComponent:theName) |error|:(missing value))
end repeat
end open
To be honest, I tested the script without the Quick Time Player chunk of code and with the extension numbers in place of mov.
The code is longer than yours but it would be faster.
Yvan KOENIG running El Capitan 10.11.0 in French (VALLAURIS, France) vendredi 2 octobre 2015 21:47:31