I would like to trim a video file per frame number rather than seconds.
So far I have tried a few options and this is the most successful one so far:
set start_trim to 5
set end_trim to 6
tell application "QuickTime Player"
activate
try
set movieFile to (the POSIX path of ("PathToMovieFolder")) & "MyMovie.mov"
on error errorMsg number errorNum
display alert errorMsg & space & errorNum message ¬
"An error occured trying to find the file " & movieFile & "." & return & ¬
"Check the file path exists, and the file spelling." as warning giving up after 60
end try
try
open movieFile with presenting
delay (0.25)
present document 1
delay (0.25)
trim document 1 from start_trim to end_trim
display alert errorMsg & space & errorNum message ¬
"An error occured trying to open & play the file " & movieFile & "." & return & ¬
"Check the file path exists, and the set delay time" as warning giving up after 60
end try
end tell
What it does is that it trims it to seconds rather than exact frames.
Any ideas on how to solve this?
Frame is not in the QuickTime Player dictionary. However, it is in the QuickTime Player 7 dictionary. If you need to trim using frames rather than seconds, I would suggest finding a copy of QuickTime Player 7.
or maybe you could do something like this:
set FPS to 29.97
set start_trim to 5
set end_trim to 7
set startFrame to start_trim / FPS
set endFrame to end_trim / FPS
tell application "QuickTime Player"
activate
trim document 1 from startFrame to endFrame
end tell
Related
For the life of me I can't figure out what's causing this error. I have made sure to disable smart quotes, but keep getting the same error. The script itself is intended to automate handbrake video conversion, and admittedly I'm very new to playing with apple script but can't figure out what's causing this. Any help would be greatly appreciated.
Here is the full code in case it helps:
on adding folder items to this_folder after receiving these_items
with timeout of (720 * 60) seconds
tell application "Finder"
--Get all MOV files that have no label color yet, meaning it hasn't been processed
set allFiles to every file of entire contents of ("Macintosh HD:Users:MacMini:Downloads:Downloaded" as alias) whose (name extension is "mov" and label index is 0)
--Repeat for all files in above folder
repeat with i from 1 to number of items in allFiles
set currentFile to (item i of allFiles)
try
--Set to gray label to indicate processing
set label index of currentFile to 7
--Assemble original and new file paths
set origFilepath to quoted form of POSIX path of (currentFile as alias)
set newFilepath to (characters 1 thru -5 of origFilepath as string) & "mp4'"
--Start the conversion
set shellCommand to "nice /Applications/HandBrakeCLI -i " & origFilepath & " -o " & newFilepath & " --preset=\"Fast 720p30\" --optimize ;"
tell current application
do shell script shellCommand
end tell
--Set the label to green in case file deletion fails
set label index of currentFile to 6
--Remove the old file
set shellCommand to "rm -f " & origFilepath
tell current application
do shell script shellCommand
end tell
on error errmsg
--Set the label to red to indicate failure
set label index of currentFile to 2
end try
end repeat
end tell
end timeout
end adding folder items to
It's a typical copy & paste error:
Replace all occurrences of & with &
It's an apple scrpit question;
Running on Mac I found on the web a script that should be helpfull to rotate my MOV so they behave normally.
But I cant get it wright.
Suppose the movie that I want to work with reside here; /Users/pauldupuis/Documents/MTL/P1280602.MOV
and I want the newly rotate movie to be in the same folder /Users/pauldupuis/Documents/MTL
Can somebody fill the blanks for me and put these info in the script below so that it can work?
tell application "QuickTime Player"
set m to (get movie 1)
rotate m by -90
save self contained m in (choose file name with prompt "save self contained movie")
end tell
Paul the following is for Quicktime Player 7 which you can download for free from Apple's website.
tell application "QuickTime Player 7"
tell front document
# Get the filename
set mName to name
# Get the full path
set mPath to path
# Get the full path of the folder file is in...
try
set mFolder to (do shell script "dirname " & mPath)
on error eStr
log eStr
beep
# oh no, something went wrong...
return
end try
# Prepare new filename
set dotPos to offset of "." in mName
set fName to text 1 thru (dotPos - 1) of mName
set fExt to text (dotPos) thru -1 of mName
log fName & " - " & fExt
set newFile to mFolder & "/" & fName & "-rotated" & fExt
# Do rotation
rotate track "Video Track" by -90
# Save to new file...
save self contained in (newFile as POSIX file)
end tell
end tell
I've been searching google.com a couple of hours trying to find a way to do this, but there is no answer. Everywhere is resize to the longest size, but nothing about resize to the specified width only.
Is there any way in Automator or AppleScript to resize images to a specified width only, instead of just the longest size? I need my output images to be a specific width ony (e.g 200px).
You can do this with plain AppleScript and a shell utility entitled sips:
on open droppings
repeat with everyDrop in droppings
set originalFile to quoted form of POSIX path of (everyDrop as text)
tell application "Finder"
set originalName to everyDrop's name
set imageContainer to (everyDrop's container as text)
end tell
set reSizedName to "200W" & originalName
set outputPath to quoted form of POSIX path of (imageContainer & reSizedName)
do shell script "sips --resampleWidth 200 " & originalFile & " --out " & outputPath
end repeat
end open
on run
display dialog "Drop some Image Files to Re-size them all to 200 pixels wide" buttons {"Aye Aye"} default button "Aye Aye"
end run
This preserves the aspect ratio of the original image, and simply re-sizes the width to 200 pixels. Hopefully you can see where you can make the changes necessary for your own workflow.
If you want to drop a folder of images as well as individual files, try this as a droplet:
on open droppings
repeat with everyDrop in droppings
if (info for everyDrop)'s folder is true then
tell application "Finder" to set allImageFiles to everyDrop's every file
repeat with eachFile in allImageFiles
my SetWidthTo200(eachFile)
end repeat
else
my SetWidthTo200(everyDrop)
end if
end repeat
end open
to SetWidthTo200(img)
set originalFile to quoted form of POSIX path of (img as text)
tell application "Finder"
set originalName to img's name
set imageContainer to (img's container as text)
end tell
set reSizedName to "200W" & originalName
set outputPath to quoted form of POSIX path of (imageContainer & reSizedName)
do shell script "sips --resampleWidth 200 " & originalFile & " --out " & outputPath
end SetWidthTo200
on run
display dialog "Drop some Image Files to Re-size them all to 200 pixels wide" buttons {"Aye Aye"} default button "Aye Aye"
end run
There is still no error-checking or checking to be sure that the files are indeed image files, so keep that in mind.
Here's a summary from this OSX Tips using automator to resize images
open "Automator"
File > New > Service
Settings:
Service received selected: "image files"
in "Finder"
in the left pane, find for action named "Get Selected Finder Items"
Next look for action "Scale Images"
If you wish to replace original, choose "Don’t Add" when it ask
"would you like to add a Copy Finder Items action", otherwise, choose add
In order to be able to choose the highest pixels before scaling, click on Options at the right of results, tick
"show this action when the workflow run"
I'm looking for a script that will save the url's of my open tabs in Safari to a text document, so that I can open them later (its 10+ tabs). I found this script online:
[applescript]
tell application "Safari"
--Variables
set windowCount to number of windows
set docText to ""
--Repeat for Every Window
repeat with x from 1 to windowCount
set tabcount to number of tabs in window x
--Repeat for Every Tab in Current Window
repeat with y from 1 to tabcount
--Get Tab Name & URL
set tabName to name of tab y of window x
set tabURL to URL of tab y of window x
set docText to docText & "" & tabName & "" & linefeed as string
end repeat
end repeat
end tell
--Write Document Text
tell application "TextEdit"
activate
make new document
set the text of the front document to docText
end tell
[/applescript]
But when I try to run this I get the error
Expected expression, but found "/"
and it marks the last line, [/applescript] as being wrong. I've searched for the error but can't seem to find it. anyone got an idea?
You probably should remove the [applescript] and [/applescript] lines when you put the script into the AppleScript Editor.
Remove [applescript] and [/applescript]
I am making an applescript that converts a folder of flv and f4v files to mp4 files and then uploads the to a server via filezilla. How would I use applescript to upload to a server through Filezilla? Here is my code:
--Install handbrakecli into /usr/bin/
--on adding folder items to this_folder after receiving these_items
with timeout of (720 * 60) seconds
tell application "Finder"
--Get all flv and f4v files that have no label color yet, meaning it hasn't been processed
set allFiles to every file of entire contents of ("Macintosh HD:Users:Chase:auto_convert:nope" as alias) whose ((name extension is "flv" or name extension is "f4v") and label index is 0)
--Repeat for all files in above folder
repeat with i from 1 to number of items in allFiles
set currentFile to (item i of allFiles)
try
--label to indicate processing
set label index of currentFile to 3
--Assemble original and new file paths
set origFilepath to quoted form of POSIX path of (currentFile as alias)
set newFilepath to (characters 1 thru -5 of origFilepath as string) & "mp4'"
--Start the conversion
tell application "Terminal"
do shell script "HandBrakeCLI -i " & origFilepath & " -o " & newFilepath
end tell
--Set the label to red because this is the file that has been converted
set label index of currentFile to 6
--Remove the old file
on error errmsg
--Set the label to red to indicate failure
set label index of currentFile to 2
end try
end repeat
set extensionToFind to "mp4"
set topLevelFolder to "Macintosh HD:Users:Chase:auto_convert:nope" as text
set pathCount to count of topLevelFolder
set mp4Files to files of entire contents of folder topLevelFolder whose name extension is extensionToFind
if mp4Files is {} then return
set mp4Folder to "Macintosh HD:Users:Chase:auto_convert:yep"
move mp4Files to mp4Folder
end tell
end timeout
--end adding folder items to
Not a good idea, because Filezilla has no applescript support. I've always been surprised that Cyberduck doesn't either. But see:
http://discussions.apple.com/thread/2588937?start=0&tstart=0
.... on which there are good directions; curl in shell, or (at the end of the page) URL Access Scripting, which is a scripting addition that should be installed on your Mac. URL Access Scripting example:
tell application "URL Access Scripting"
upload filepathtoUpload to "ftp://username:password#domain.com/SOME/PATH/filename.jpg" replacing yes without binhexing
end tell