script to import files from folder into cues in group

130 views
Skip to first unread message

Paul

unread,
Jun 13, 2023, 5:21:47 AM6/13/23
to QLab
-- import files from folder into cues in group
-- (for Jason King)

-- Preparation before running this script:
-- set the Notes of this cue to the file path of the folder you want to import from (directly or via OSC)
--  set the groupCueNum variable below to your group cue (or the group cue will be created with default number)
-- adjust the displayDuration variable below to suit your application
--  in Settings - Templates, set the default stage for video cues and defaults for group playlist cues (loop etc)
--  (otherwise you will get broken video cues as there's no way to set the stage for video from a script)
-- you may also want to check Settings->General-> File Management tab to copy/not copy files as suits your application

-- adjust the configuration items below to suit
-- the group cue number (NB cue "5" is different from cue 5 - generally you want quotes around the cue "number")
set groupCueNum to "321"
set displayDuration to 1.5

tell application id "com.figure53.QLab.5" to tell front workspace
-- get the folder to import from the notes of this cue
set thiscue to last cue whose running is true and q type is "Script"
set importFolder to notes of thiscue

set AppleScript's text item delimiters to linefeed
set actionList to {}

----------- set up logging to file ----------------
-- use the workspace name as log file name
set AppleScript's text item delimiters to "."
set logfileName to (POSIX path of (path to desktop)) & (first text item of ((q number) as string)) & "_log.txt"
try
set logFile to open for access logfileName with write permission
write linefeed & ((current date) as string) & tab & "Script started, group cue " & groupCueNum & ",  import from  " & importFolder & linefeed to logFile starting at eof
on error errorMessage
display notification "error opening log file " & errorMessage
end try

------------------- delete existing video cues in specified group -----------------
try
set groupCue to cue groupCueNum
set deleteCues to every cue whose (parent is groupCue and q type is "Video")
repeat with cue2del in deleteCues
set end of actionList to "deleted " & (q display name of cue2del)
delete cue id (uniqueID of cue2del) of parent of cue2del
try
write ((current date) as string) & tab & "deleted cue " & (q display name of cue2del) & linefeed to logFile starting at eof
end try
end repeat
on error errorMessage
-- we got an error, probably because the group doesn't exist, so create it
if errorMessage contains "Can’t get cue" then

-- make a group, set mode to playlist and put today date in notes
make type "Group"
set groupCue to last item of (selected as list)
set q number of groupCue to groupCueNum
set mode of groupCue to playlist
set q name of groupCue to "created " & (current date)
try -- log action to file
write linefeed & ((current date) as string) & tab & "created group, number " & groupCueNum & linefeed to logFile starting at eof
end try
else
display notification errorMessage
end if
end try
------------------- import files from specified folder and make video cues ----------------
try
-- use a shell script to get a list of files in the chosen folder
-- approach here is to import everything in folder and remove anything invalid
set importFiles to every paragraph of (do shell script "ls -1 " & quoted form of importFolder)
on error errorMessage
display notification errorMessage with title "An Error occured"
return 1
end try
--set AppleScript's text item delimiters to linefeed
--display dialog importFiles as text with title "files to import"

set importedlist to {}
repeat with myfile in importFiles
make type "Video"
set newcue to last item of (selected as list)
-- set the path to the video file
set filepath to importFolder & "/" & myfile
set file target of newcue to filepath

-- check for missing file path (probably not an valid video / image file)
if (file target of newcue) is missing value then
display notification "there may be a problem with the file " & (filepath)
-- delete the broken cue
set cue2del to newcue
delete cue id (uniqueID of cue2del) of parent of cue2del
try -- log action to file
write ((current date) as string) & tab & "invalid image/video file " & myfile & linefeed to logFile starting at eof
end try
else
set duration of newcue to displayDuration
set newCueID to uniqueID of newcue
move cue id newCueID of parent of newcue to end of groupCue
try -- log action to file
write ((current date) as string) & tab & "created cue for " & (q display name of newcue) & linefeed to logFile starting at eof
end try
set end of actionList to "imported " & (q display name of newcue)
end if
end repeat
set notes of groupCue to "imported " & (current date)
-- uncomment next line to show results when using script interactively
-- display dialog actionList as text with title "actions completed"

-- uncomment next line to start the playlist group cue
--start groupCue
end tell
Reply all
Reply to author
Forward
0 new messages