Friday, December 15, 2017

#1 2016-07-23 09:39:51 am

tsnider
Member
Registered: 2011-05-19
Posts: 12

Issue with storing paths in lists and records

Hello I'm having some issues with an Xcode applescriptObjC script I'm writing that is starting to drive me batty.  I was hoping another set of eyes might help me catch something I'm missing.  The overall script is large so I'm hoping to just post the main parts where I think the issue is located. 

Here is a little description of what I'm trying to do.  I have an action(singleTCDUB) in my script that is currently working fine.  It takes all of user selectable variables I have (source path, destination path, new Filename, selected extension) and then passes those variables to a createTCDUB function which uses all of those variables and ffmpeg(using shell scripts) to stitch multiple video files together.

Applescript:


on singleTCDUB_(sender)

-- This is used in createTCDUB to determine the method used for processing.
set isMerge to 0

if formatSelection as text equals "MOV" then
set currentSelectedExtension to "MOV" as text

else if formatSelection as text equals "MXF" then
set currentSelectedExtension to "MXF" as text

else if formatSelection as text equals "MP4" then
set currentSelectedExtension to "MP4" as text

else if formatSelection as text equals "MTS" then
set currentSelectedExtension to "MTS" as text

else if formatSelection as text equals "P2 Proxy" then
set currentSelectedExtension to "MP4" as text
set isMerge to 1

end if

-- Log out to the console what the current extension is
log "The selected extension is = " & currentSelectedExtension

-- This deals with some UI considerations
tell createButton to setEnabled_(false)
progressBar's setHidden_(false)
progressBar's setDoubleValue_(0)
updateUI("","","Starting")

-- This makes sure the paths are set
if theFolder equals "" or theDestinationFolder equals "" then
display alert ("Please select your source or destination")
tell createButton to setEnabled_(true)
return
end if

-- This starts the file processing
createTCDUB_(currentSelectedExtension,theDestinationFolder,theFolder,FilenameText,isMerge)

-- after completetion this re-enables the start button, etc
tell createButton to setEnabled_(true)
updateUI("","","")

end singleTCDUB_

As I mentioned this is working fine,  However, I also wrote a few new actions that allows me to batch process multiple selections.  Essentially this is composed of three functions.  addToBatch, removeFromBatch, and batchTCDUB.  The idea is that addToBatch will store all of the currently selected variables, removeFromBatch will allow a user to remove a set of variables before processing, and batch TCDUB will loop through the list containing all of the records and then pass them one by one into the same create TCDUB function that the single TCDUB action does. The batch functions seem to work fine but once the createTCDUB function runs it can never find any files in the source path.  Here are the batch functions.

Applescript:


on addToBatch_(sender)

-- This is used in createTCDUB to determine the method used for processing.
set isMerge to 0

if formatSelection as text equals "MOV" then
set currentSelectedExtension to "MOV" as text

else if formatSelection as text equals "MXF" then
set currentSelectedExtension to "MXF" as text

else if formatSelection as text equals "MP4" then
set currentSelectedExtension to "MP4" as text

else if formatSelection as text equals "MTS" then
set currentSelectedExtension to "MTS" as text

else if formatSelection as text equals "P2 Proxy" then
set currentSelectedExtension to "MP4" as text
set isMerge to 1

end if

-- Log out to the console what the current extension is
log "The selected extension is = " & currentSelectedExtension

-- This makes sure the paths are set
if theFolder equals "" or theDestinationFolder equals "" then
display alert ("Please select your source or destination")
tell createButton to setEnabled_(true)
return
end if

-- This adds the current user variables to the list
set tempList to {}
set end of tempList to {batchCurrentSourceFolder:theFolder, batchCurrentDestinationFolder:theDestinationFolder, batchFormatSelection: formatSelection, batchCurrentFilenameText: filenameText, batchCurrentSelectedExtension: currentSelectedExtension, batchIsMerge: isMerge}

tell theArrayController -- this physically adds it to the array
addObjects_(tempList)
end tell

end addToBatch_

on removeFromBatch_(sender)
-- this removes the selected table data from the table
set selectionIndex to theArrayController's selectionIndex()
tell theArrayController
remove_(selectionIndex)
end tell
end removeFromBatch_


on batchTCDUB_(sender)
-- this exports the table data to a list
tell theArrayController to set theList to arrangedObjects() as list
log theList

-- the following repeats through the list and set the variables and then sends to createTCDUB.
repeat with i from 1 to count of theList
set currentItem to item i of theList

set currentSelectedExtension to batchCurrentSelectedExtension of currentItem
set currentDestinationFolder to batchCurrentDestinationFolder of currentItem
set currentSourceFolder to batchCurrentSourceFolder of currentItem
set currentFilenameText to batchcurrentFilenameText of currentItem
set isMerge to batchIsMerge of currentItem

-- This deals with some UI considerations
tell createButton to setEnabled_(false)
progressBar's setHidden_(false)
progressBar's setDoubleValue_(0)
updateUI("","","Starting Next Card")


createTCDUB_(currentSelectedExtension,currentDestinationFolder,currentSourceFolder,currentFilenameText,isMerge)
end repeat

end batchTCDUB_

Here is the beginning code from createTCDUB.  This is up to the point where I have my problems which I will describe after the code

Applescript:

on createTCDUB_(currentSelectedExtension,currentDestinationFolder,currentSourceFolder,currentFilenameText,isMerge)

-- this is a console output to check the incoming variables
log "Here is a variable check from incoming batch files"
log "currentFilenameText = " & currentFilenameText
log "currentSourceFolder = "& currentSourceFolder
log "currentDestinationFolder = " & currentDestinationFolder
log "currentSelectedExtension = " & currentSelectedExtension
log "isMerged = " & isMerge


-- add a random number if the default filename is used
set rNumber to current application's (random number from 1 to 1000)
if currentFilenameText equals "defaultFilename" then
set tempFileName to currentFilenameText as text & "_" & rNumber & "_TC.MP4"
set finishedFileName to currentFilenameText & "_" & rNumber as text
log "The filename for this clip will be " & finishedFileName & "_TC.MP4"

else
set tempFileName to currentFilenameText as text & "_TC." & currentSelectedExtension as text
set finishedFileName to currentFilenameText as text
log "The filename for this clip will be " & finishedFileName & "_TC.MP4"

end if


-- attempts to put every filename of the selected extension into a list
set file_list to ""
try
tell application "Finder"

set file_list to name of every file of entire contents of currentSourceFolder where name extension is currentSelectedExtension as text
end tell
end try

-- logs to the console the file list
log "file_list = " & file_list

-----the rest of my processing code goes here---

end createTCDUB_

This is where the problem seems to be occurring.  When createTCDUB is fired by the singleTCDUB action then this all works perfectly and log file_list list out all of the files to be processed.  If createTCDUB is fired by batch TCDUB then log file_list is always empty.  The weirdest thing to me is that when logging them out to the console the paths for currentSourceFolder and destination folder, in createTCDUB are identical when coming from both actions.  However,  it works from the single and not from the batch.  I've experimented with a myriad of options including using "quoted form of the POSIX path of" when storing and POSIX file when re-assigning but then it doesn't seem to work through either action. 

Any help or ideas that anyone has would be greatly appreciated, as I'm still stumped after a few days of tinkering.  I can share more code if needed as well.

Thanks in advance.

Tim

Last edited by tsnider (2016-07-23 10:10:54 am)

Offline

 

#2 2016-07-23 09:18:32 pm

tsnider
Member
Registered: 2011-05-19
Posts: 12

Re: Issue with storing paths in lists and records

Looking through my post again, I probably should also include for you the action that sets the paths.  Here is that piece as well.

Applescript:



-- SET SOURCE PATH
on setSourcePath_(sender)
set basePath to choose folder with prompt "Where are the files you would like to combine?"
set theFolder to basePath
sourceLabel's setStringValue_(POSIX path of theFolder)

-- IF NO DESTINATION IS SET THIS SETS DESTINATION TO DESKTOP
if theDestinationFolder is equal to "" then
set destinationPath to (path to Desktop Folder)
set theDestinationFolder to destinationPath
destinationLabel's setStringValue_(POSIX path of theDestinationFolder)
end if

--log "Values as they are written"

log ("The Source Folder = " & POSIX path of theFolder)
log ("The Destination Folder = " & POSIX path of theDestinationFolder)

end setSourcePath_

Offline

 

#3 2016-07-23 09:34:51 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5199

Re: Issue with storing paths in lists and records

If currentSourceFolder is a path, that would probably explain things. It should be a file of some sort -- alias, «furl», Finder reference -- not a path.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#4 2016-07-23 10:16:17 pm

tsnider
Member
Registered: 2011-05-19
Posts: 12

Re: Issue with storing paths in lists and records

Thank you!  I'm still fairly new to applescriptObjC so I'm going to read up on aliases now to try and figure this out.

One follow up question.  If I create the alias on the first variable when I store the path, for example:

Applescript:

set basePath to alias choose folder with prompt "Where are the files you would like to combine?"

Will the alias carry on through out moving it between variables?

Offline

 

#5 2016-07-23 10:32:18 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5199

Re: Issue with storing paths in lists and records

No -- you store the path. But you need to pass a file object to the Finder. If your path is an HFS path, you can use something like thePath as alias; if it's a POSOX path, something like thePath as POSIX file.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#6 2016-07-23 10:42:22 pm

tsnider
Member
Registered: 2011-05-19
Posts: 12

Re: Issue with storing paths in lists and records

That was it!

Thanks again! 

Tim

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)