is pointless anyway because the literal string is a POSIX path.
I recommend to use an alias with an HFS path (starting with a disk name). And remove the return line because a return statement on the top level will exit the script. Add an else clause instead.
This small script is to be attached to a longer working script. I am now attaching the whole script.
The script is to create short video clips of longer video files found in a given folder. At the time, I’ve started this project I was to execute the script subfolder by subfolder individually. The situation has changed where I can no longer execute the script subfolders by subfolders.
To speed uptake execution time, I have to verify the clip already exist. If it does, the script is toby pass that file and go to the next one.
The script is almost complete. I only have problems with verifying if the file exist. I’ve been trying different combination without success. THANKS!
You’re not going to have any success if you keep trying to use HFS paths and ignore Stefan’s point about not using Volumes.
Given that you’re already using ASObjC, and you’re having problems with how HFS paths work, you’d probably be better to avoid them and the Finder altogether:
The situation here is that I do not know the differences between HFS’ path and alias. Neither I do understand their behaviour. As of using AObjC, sincerely I do have no experiences.
This script has been growing up by browsing through the internet and asking questions on the MacScripter forum. I have been very fortunate to have people like you on MacScripter.
The AObjC module works very good in building short video clips. I have been using it over the weekend and found I’ve needed to improve the process in which the script was to be executed.
I will be running the script as many time I will be having “xx” subfolders being created. I then need to find a mechanism which avoid trying to recreate clips which have already been created. This is what I what I was trying to do last. i.e skip re-creating a video 15 seconds video which has already been created.
Where could I get some information in order to code the last part being needed?
If I understand correct, I should be using POSIX path names instead of HFS path names?
You use HFS paths if you want to create aliases to pass to applications like the Finder. HFS paths are colon-delimited and never begin with Volumes – they begin with the name of the volume, as it appears in the Finder. POSIX paths are slash-delimited, and for remote volumes will begin with “/Volumes/”.
Where the script says:
on createclipvideo(theURL)
set theAsset to current application's AVURLAsset's assetWithURL:theURL
set destPath to (theURL's |path|()'s stringByDeletingPathExtension()'s stringByAppendingString:"-clip")'s stringByAppendingPathExtension:"mp4"
Insert the following two lines:
set destURL to current application's NSURL's fileURLWithPath:destPath
if (destURL's checkResourceIsReachableAndReturnError:(missing value)) as boolean then return
That will check if the file exists, and if so go no further with it.
Unfortunately at the moment, it keeps running even if the “-clip” file already exist.
Original file : pzv01001.mp4
First time the script run create: pzv01001-clip.mp4
Second time the script run creates : pzv01001-clip-clip.mp4
Third time the script run creates : pzv01001-clip-clip-clip.mp4
on createclipvideo(fvideo)
set thePath to POSIX path of (fvideo)
set theURL to current application's NSURL's fileURLWithPath:thePath
set theAsset to current application's AVURLAsset's assetWithURL:theURL
set destPath to (theURL's |path|()'s stringByDeletingPathExtension()'s stringByAppendingString:"-clip")'s stringByAppendingPathExtension:"mp4"
set destURL to current application's NSURL's fileURLWithPath:destPath
if (destURL's checkResourceIsReachableAndReturnError:(missing value)) as boolean then return
It doesn’t really. It’s just that as you search the folder each time for all .mp4 files, it catches the -clip files and therefore tries to make clips of them. You need to filter them out at the beginning.
So change this line:
set thePred to current application's NSPredicate's predicateWithFormat_("pathExtension == %@", "mp4")
To this:
set thePred to current application's NSPredicate's predicateWithFormat:"(pathExtension == %@) AND (lastPathComponent.stringByDeletingPathExtension ENDSWITH %@)" argumentArray:{"mp4", "-clip"}
At the moment with the new line it does not get into the repeat with aURL in theURLs loop.
If should only process “.mp4” files but not those mp4 files ending by “-clip.mp4”
For example, the first time “pzv01001.mp4” should be processed to create “pzv01001-clip.mp4”.
The next time the script is being processed, a 15 second clip should not be created for “pzv01001.mp4” s because “pzv01001-clip.mp4” already exist.
Let’s say:
pzv01001.mp4 look if (pzv01001-clip.mp4 exist ; yes-skip ; no process to create pzv01001-clip.mp4)
pzv01002.mp4 look if (pzv01002-clip.mp4 exist ; yes-skip ; no process to create pzv01002-clip.mp4)
set thePred to current application's NSPredicate's predicateWithFormat:"(pathExtension == %@) AND (NOT lastPathComponent.stringByDeletingPathExtension ENDSWITH %@)" argumentArray:{"mp4", "-clip"}
WOW! This one was a VERY big one for me to accomplished.
My process of recording videos with short clips that accompany them will make it easier for me. This is something I wanted to do for many years. I knew this was going to be a VERY BIG challenge for me.
I want to say thanks to all of those who helped me out with this. A special thanks to Stefank and to Shane Stanley. Impossible for me to this without your help.
I will try in the future to be more careful with HFS path ( no “Volumes” and POSIX path (/) “with remote volume (external disk) will start with /Volumes/” paths.