Okay I am trying to get this script to work. It works up to the point I try to find the temp file for the .mp4 file. I am using the shell script "find" because I am not able to get
with the find I get this back because the file exists but the script still moves the parent file.
tell current application
do shell script "find '/Users/ifbell/Desktop/videofinished/''MySource.mp4'.sb-*"
--> "/Users/ifbell/Desktop/videofinished/MySource.mp4.sb-5bfb4088-1FQIwv"
the script skips by this section when implemented.
set xfileExists to (the file in the mypath whose name contains finname and extension contains ".mp4.sb-")
display alert xfileExists giving up after 5
if exists xfileExists as POSIX file then set filetrue to "yes"
I have commented out the on idle for the moment but they get implemented when this gets built as an app.
I would love to run this just as a folder action but since I upgraded to 10.10.x I have lost my ability to use folder actions.
I know I am missing something but I am unable to figure out what.
Here is the whole script.
global finname
global theWatchedFolder
global filetrue
global xflileExists
global mypath
property fileName : {}
set SBexists to 1
property nameslist : {}
property filetrue : "no"
property xfileExists : {}
set finname to {}
set n to 0
set theWatchedFolder to "Macintosh HD:Users:ifbell:Desktop:videofinished" as string
set finloc to "/Users/ifbell/Desktop/processedvid/" as string
set mypath to "Macintosh HD:Users:ifbell:Desktop:videofinished:"
#set filetrue to tempexist(xfileExists)
### this is used to clear the lists after runs
property cleanlist : {}
### get finished video files
#on idle
tell application "Finder"
try
set folderFiles to (every file in the folder theWatchedFolder whose name extension is "mp4")
set the item_count to the number of items in the folderFiles
if item_count is equal to 0 then return 15
repeat with currentFile in folderFiles
set currentFileName to (the name of currentFile)
#display alert currentFileName giving up after 5
copy currentFileName to the end of nameslist
end repeat
if nameslist is equal to oldfileName then return 15
set oldfileName to the content of cleanlist
on error errTxt number errNum
end try
end tell
display alert (count of nameslist) giving up after 5
####find the matching parent files and move them
tell application "Finder"
set AppleScript's text item delimiters to "."
repeat with n from 1 to count of nameslist
try
copy (item n of nameslist) to fileName
set {finname, nameExt} to {text 1 thru text item -2, text item -1} of fileName
display alert 4 giving up after 5
#tempexist(mypath, fileName) of me
set fileloc to "/Users/ifbell/Desktop/videoTBP/" & finname & ".mov" as string
display alert 5 giving up after 5
if exists POSIX file fileloc as alias then
display alert 6 giving up after 5
my tempexist(xfileExists)
display alert "8=" & filetrue giving up after 5
if filetrue = "no" then
display alert "file exists=" & filetrue
do shell script "mv " & quoted form of fileloc & " " & quoted form of finloc & ""
display notification finname & " has been moved"
my sendMail(finname)
end if
end if
set SBexists to 0
end try
end repeat
copy nameslist to oldfileName
set nameslist to the contents of cleanlist
end tell
set AppleScript's text item delimiters to ""
return 30
#end idle
####Send mail
on sendMail(finname)
display alert "mailing " & finname giving up after 5
set recipientName to "xxxx"
set recipientAddress to "xxxxxxx"
set theSubject to "compressor has processed the following files"
set theContent to "The file " & finname & " have been completed."
tell application "Mail"
##Create the message
set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}
##Set a recipient
tell theMessage
make new to recipient with properties {name:recipientName, address:recipientAddress}
##Send the Message
send
end tell
end tell
end sendMail
on tempexist(xfileExists)
display alert 7 giving up after 5
tell application "Finder"
try
display alert "7.A" giving up after 5
#set xfileExists to do shell script ("find " & quoted form of POSIX path of mypath & quoted form of fileName & ".sb-*")
set xfileExists to (the file in the mypath whose name contains finname and extension contains ".mp4.sb-")
display alert xfileExists giving up after 5
if exists xfileExists as POSIX file then set filetrue to "yes"
display alert filetrue
end try
end tell
return filetrue
end tempexist