Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 11, 2010, 12:32 PM   #1
physaux
macrumors newbie
 
Join Date: Feb 2010
How can I set a variable in applescript??

I am trying to set a variable that will hold the length of a movie in quicktime.
Here is my try at it:

tell application "QuickTime Player"
set movie_length as ??????????

How do I do that??? Pleaaaase help me!
physaux is offline   0 Reply With Quote
Old Feb 11, 2010, 01:46 PM   #2
mysterytramp
macrumors 65816
 
mysterytramp's Avatar
 
Join Date: Jul 2008
Location: Maryland
Quote:
Originally Posted by physaux View Post
I am trying to set a variable that will hold the length of a movie in quicktime.
Here is my try at it:

tell application "QuickTime Player"
set movie_length as ??????????

How do I do that??? Pleaaaase help me!
AppleScript is fairly forgiving when it comes to assigning variables.

set movie_length to 120 -- stores an integer
set movie_length to "2 hours" -- stores a string
display dialog movie_length -- most of the time, AS will convert numbers to string for dd messages
display dialog (movie_length as string) -- but sometimes you need to coerce the variable

If you're having problems, you do realize that a tell statement needs an "end tell", right?

so ...

Code:
tell application "QuickTime Player"
     set movie_length to 120
end tell
do this help?

mt
__________________
What looks large from a distance, close up ain't never that big.
mysterytramp is offline   0 Reply With Quote
Old Feb 11, 2010, 02:03 PM   #3
physaux
Thread Starter
macrumors newbie
 
Join Date: Feb 2010
yes thank you that helped. I have another question, I am trying to shorten a video, and I am pretty much done.

Code:
tell application "QuickTime Player"
	select at 0 to new_time
	????????????
end tell
I am trying to trim the length of the video(inplace of the ???? above), but it is never working! I have tried:

Code:
trim front document
trim
trim document
But everytime I do that, it doesn't trim it properly, just nothing happens! I know the right portion of the timeline is selected because I have run the script with a delay after the 'select' line, and I can see that the right part is selected. Now my understanding is that 'trim' is supposed to 'trim' this part. What am I doing wrong??

ps- thank you I really appreciate your help
physaux is offline   0 Reply With Quote
Old Feb 11, 2010, 03:45 PM   #4
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
You're not passing the correct arguments.

Open AppleScript Editor, go to File > Open Dictionary and select QuickTime Player. Then search for "trim" and you'll see what arguments that command takes.

edit: I merged your threads since they overlap.
kainjow is offline   0 Reply With Quote
Old Feb 11, 2010, 04:25 PM   #5
physaux
Thread Starter
macrumors newbie
 
Join Date: Feb 2010
Thanks for merging them

I searched like you said, and I found this:
Code:
trim v : Remove all content before and after the current selection
trim specifier : movie
I am very new to applescript so I really don't know how to interpret that. What is a specifier?
physaux is offline   0 Reply With Quote
Old Feb 11, 2010, 05:05 PM   #6
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
There are two arguments to trim: the start and end time in seconds, so the format is:
Code:
trim movie from seconds to seconds
If you only have one movie open, use "document 1" to refer to it, then fill in what seconds you want to trim it to.
kainjow is offline   0 Reply With Quote
Old Feb 11, 2010, 05:35 PM   #7
physaux
Thread Starter
macrumors newbie
 
Join Date: Feb 2010
Ok I have tried to do what you said, but I get an error when I try to compile. Here is a screenshot:



Just to clear things up, here is version data about the 'script editor' that I am using:


And lastly, here is the whole script, copy and pasted in

Code:
with timeout of 86400 seconds
	
	display dialog "Before beginning batch processing, make sure QuickTime Player is set to the desired export settings, and all videos to be processed are in a folder named ‘Input’ on the desktop." with icon note
	
	tell application "Finder"
		set the startup_disk to the name of the startup disk
	end tell
	
	set amount_to_trim to 30
	set user to do shell script "whoami"
	set input_folder_name to "Input"
	set input_folder to startup_disk & ":Users:" & user & ":Desktop:" & input_folder_name & ":"
	set user_desktop to startup_disk & ":Users:" & user & ":Desktop:"
	set output_folder to startup_disk & ":Users:" & user & ":Desktop:Output:"
	set file_extension to "_export.mp4"
	
	try
		tell application "Finder"
			make new folder at user_desktop with properties {name:"Output"}
		end tell
	end try
	
	try
		set the_folder_list to list folder input_folder without invisibles
		repeat with x from 1 to count of the_folder_list
			set the_file to input_folder & item x of the_folder_list
			set output_file to output_folder & item x of the_folder_list & file_extension
			tell application "QuickTime Player"
				activate
				try
					close front window
				end try
				open the_file
				trim document 1 from 0 to ((duration of document 1) - amount_to_trim)
				export front document to output_file as MPEG4 using most recent settings with replacing
				close front document
			end tell
		end repeat
	on error
		display dialog "This script requires a folder named ‘" & input_folder_name & "‘ located on the desktop." with icon stop
	end try
	
	beep
	
end timeout
Do you see what I am doing wrong?
physaux is offline   0 Reply With Quote
Old Feb 13, 2010, 12:37 AM   #8
mysterytramp
macrumors 65816
 
mysterytramp's Avatar
 
Join Date: Jul 2008
Location: Maryland
Looks like there's a difference between Leopard QuickTime Player and Snow Leopard QuickTime Player.

The "trim" line compiles fine on my system. The "export" line following needs some tweaking, however.

mt
__________________
What looks large from a distance, close up ain't never that big.
mysterytramp is offline   0 Reply With Quote
Old May 18, 2010, 05:04 AM   #9
pugu
macrumors newbie
 
Join Date: May 2008
Location: London, UK
Quote:
Do you see what I am doing wrong?
I am having exactly the same problem using QTP 7 on Snow Leopard

Code:
tell application "QuickTime Player 7"
	
	activate
	
	close every window
	
	open "/latest.mp3"
	
	set end_time to the duration of document 1
	
	tell document 1
		
		trim document from 1 to end_time
		
		export to "/latest.wav" as wave using settings preset "8 kHz 16 bit Mono"
		
	end tell
	
	quit
	
end tell
Did you ever find a solution or does anybody else know the answer?

thanks, pugu
pugu is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
String and variable concatenation in AppleScript tekboi Mac Programming 6 Apr 15, 2014 01:37 PM
Applescript newb: declaring a variable in another script. Vanilla Face Mac Programming 2 Jan 5, 2014 07:39 PM
How to set environmental variable? hajime Mac Basics and Help 3 Sep 28, 2013 09:33 PM
Applescript "Variable hdg is not defined" Dreamspinner Mac Programming 3 Feb 12, 2013 06:33 PM
AppleScript: Set variable to every XML element of a given name moonman239 Mac Programming 13 Jan 2, 2013 02:55 PM

Forum Jump

All times are GMT -5. The time now is 10:51 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC