image
image

|


Go Back   macosx.com > Design, Media, Programming & Scripting > Software Programming & Web Scripting

Reply
 
Thread Tools
  #1  
Old October 20th, 2005, 10:27 AM
Registered User
 
Join Date: May 2005
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
eliezer is on a distinguished road
Where can I learn Applescript on the Internet for free?

Is there a list on the internet with all the Applescript commands and what they do?

Also is there a web site where i can learn applescript for free? something like w3schools website but for applescript.


thanks
__________________
1.6 ghz G5, 80GB hard disk, 512mb RAM, 17 inch moniter, os x 10.4.4

dual 2 ghz G5, 19 inch moniter, os x 10.4.4
Reply With Quote
  #2  
Old October 20th, 2005, 11:07 AM
Mikuro's Avatar
Crotchety UI Nitpicker
 
Join Date: Mar 2005
Posts: 2,438
Thanks: 2
Thanked 3 Times in 3 Posts
Mikuro is on a distinguished road
Check out http://www.apple.com/macosx/features...resources.html

Specifically, download Apple's own AppleScript Language Guide, and also their Scripting Additions guide.

Once you get a basic grip on the syntax, which shouldn't take very long, just drag some apps onto Script Editor and see what their scripting dictionaries have to offer. (The Finder is located at "/System/Library/CoreServices/Finder.app", in case you don't know.)
__________________
Mac mini — 1.25GHz G4, 1GB RAM — OS 10.5.2

I'm now a four-browser man. How on earth did this happen?!

Useful programs: PithHelmet, Butler, ffmpegX, VLC, Perian, Tofu, Wcalc
Reply With Quote
  #3  
Old October 20th, 2005, 07:20 PM
Registered User
 
Join Date: May 2005
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
eliezer is on a distinguished road
ok. its going to be impossible for me to do what i want.

basically i want to make a script so that when i drag a file (some sort of movie) onto the icon, it converts that file to .mov format using ffmpegX.

then i want to make another script that will convert .mov files to .mp4 files, using quicktime pro, with specific export settings (e.g. 176x144, frame rate=15, data rate=150kbit/sec, etc.)

am i asking for way to much here and this script will be impossible to make?

please reply with what you think about this. thanks
__________________
1.6 ghz G5, 80GB hard disk, 512mb RAM, 17 inch moniter, os x 10.4.4

dual 2 ghz G5, 19 inch moniter, os x 10.4.4
Reply With Quote
  #4  
Old October 20th, 2005, 10:00 PM
Mikuro's Avatar
Crotchety UI Nitpicker
 
Join Date: Mar 2005
Posts: 2,438
Thanks: 2
Thanked 3 Times in 3 Posts
Mikuro is on a distinguished road
Wellll.....after some experimenting with ffmpegX, I would say that YES, this would be possible. ffmpegX does not have a very elegant scripting library — in fact, it looks like it's 100% generic user interface accessors — but it ought to be enough to do what you need.

What I would do is, first of all, create a preset in ffmpegX and save it (File menu). Then the first thing you do in your script is open that file. Then you'd do something like this to tell ffmpegX what file to convert and where to save it:
Code:
tell application "ffmpegX"
	tell the content view of window 1
		set the string value of text field 5 to "/Location/To/The/File/To/Convert.avi"
		set the string value of text field 2 to "/Location/To/Save/Result.mov"
		perform action button "Encode"
	end tell
end tell
Launch ffmpegX and try running that script. You'll see that it'll insert that text into the source and destination fields, just as if you'd typed it in manually. Then it'll click the Encode button which will get it all started.

QuickTIme Player has a pretty good scripting library, so I think that part should be easy enough. I know QuickTime has scripting commands for exporting movies, but I've never used them myself, so I can't say for sure if they're flexible enough.
__________________
Mac mini — 1.25GHz G4, 1GB RAM — OS 10.5.2

I'm now a four-browser man. How on earth did this happen?!

Useful programs: PithHelmet, Butler, ffmpegX, VLC, Perian, Tofu, Wcalc
Reply With Quote
  #5  
Old October 21st, 2005, 08:50 AM
Registered User
 
Join Date: May 2005
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
eliezer is on a distinguished road
ok thanks. but when i run the script i get an error message saying: "NSReceiverEvaluationScriptError: 4". I think this is because the first screen that comes has 3 options: "Register", "Enter Code" and "Try for Free". How do I make it automatically select "Try for free"?

I tried:
[perform action button "Try for free"]
but it didn't work.

What should I put in?
__________________
1.6 ghz G5, 80GB hard disk, 512mb RAM, 17 inch moniter, os x 10.4.4

dual 2 ghz G5, 19 inch moniter, os x 10.4.4
Reply With Quote
  #6  
Old October 21st, 2005, 11:58 AM
Mikuro's Avatar
Crotchety UI Nitpicker
 
Join Date: Mar 2005
Posts: 2,438
Thanks: 2
Thanked 3 Times in 3 Posts
Mikuro is on a distinguished road
Ahhh, yeah. I'm not sure why you can't say [button "Try for free"] here, but it gives me the same error. Don't worry, there are other ways to refer to buttons. But before I tell you how to do it, let me explain how I figure this stuff out to begin with.

The first step is to open ffmpegX and just leave the window you want to manipulate open. Then go to Script Editor and start messing around. Just about every application lets you access "window x", where x is a number. The active window is window 1. So the first thing to do is "get window 1". This takes window 1 and stores it, so you can refer to it later as "the result". (Alternatively, you can just say "window 1" everywhere, but this method becomes a lot simpler when you're dealing with things like "group 1 of tab group 1 of window 1", so it's a good idea to get comfortable with it.)

Now you want to see what "the result" (window 1) has to offer. It's a good idea to look in the scripting dictionary of any app you're dealing with. So drag ffmpegX from the Finder onto the Script Editor icon, and look for the "Window" class (it's under the "Application Suite" section).

There you'll see, right at the top, a list of elements it contains. Boxes, browsers, buttons....buttons! That's what we want. (We already knew that, but now you know where to look for this stuff.)

So, let's say [return every button of the result]. You'll get a bunch of cryptic descriptions of buttons like button id 29 of window id 7 of application "ffmpegX". So which one is the 'Try for free' button? To find that out, replace this line with [return the title of every button of the result]. That returns a much easier to read list: {"Try for free", "Enter code", "Register"}. 'Try for free' is the first button in that list. That means we can refer to it as "button 1".

SO, cut out that line we just made, and replace it with [perform action button 1 of the result]. And there ya go.

You should also add an IF statement to be sure "window 1" is the "Please register" window. After all, it's possible you'll run this script after you've already loaded ffmpegX, in which case that window won't be open. That's easy enough. So, now, the complete script to dismiss this window:
Code:
tell application "ffmpegX"
	if the title of window 1 is "Please register" then
		perform action button 1 of window 1
	end if
end tell
__________________
Mac mini — 1.25GHz G4, 1GB RAM — OS 10.5.2

I'm now a four-browser man. How on earth did this happen?!

Useful programs: PithHelmet, Butler, ffmpegX, VLC, Perian, Tofu, Wcalc
Reply With Quote
  #7  
Old October 22nd, 2005, 07:27 PM
Registered User
 
Join Date: May 2005
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
eliezer is on a distinguished road
thanks a lot for your help. i really appreciate it.

this is what i have so far:

Code:
tell application "ffmpegX"
	if the title of window 1 is "Please register" then
		perform action button 1 of window 1
	end if
	tell the content view of window 1
		set the string value of text field 5 to "/Location/To/The/File/To/Convert.avi"
		set the string value of text field 2 to "/Users/admin/Desktop/XYZ.mov"
		perform action button "Encode"
	end tell
end tell
What i want to do next is:
1) Make the file to be converted be the file that i drop onto the script icon.
2) Tell ffmpegX the settings for the target format. (I know you told me create a Preset format but i had trouble loading it)
3) I need to do something about what the file will be saved as. I want the file to be saved to the desktop, but I don't want the file to be saved as XYZ.mov. I want each file to be saved as something else.

If you don't know how to do this stuff, or if it's not possible, it's not a problem, you've helped me enough already. thanks


Also, i didn't quite understand this bit:
So, let's say [return every button of the result]. You'll get a bunch of cryptic descriptions of buttons like button id 29 of window id 7 of application "ffmpegX". So which one is the 'Try for free' button? To find that out, replace this line with [return the title of every button of the result]. That returns a much easier to read list: {"Try for free", "Enter code", "Register"}. 'Try for free' is the first button in that list. That means we can refer to it as "button 1".
Where do i type in the stuff in the square brackets?


Thanks Mikuro
__________________
1.6 ghz G5, 80GB hard disk, 512mb RAM, 17 inch moniter, os x 10.4.4

dual 2 ghz G5, 19 inch moniter, os x 10.4.4
Reply With Quote
  #8  
Old October 23rd, 2005, 01:54 PM
Mikuro's Avatar
Crotchety UI Nitpicker
 
Join Date: Mar 2005
Posts: 2,438
Thanks: 2
Thanked 3 Times in 3 Posts
Mikuro is on a distinguished road
I just realized, there's actually a MUCH better way of getting the source file into ffmpegX. We don't need to be messing around with the text field at all. All we have to do is tell the FINDER to open our source movie with ffmpegX. That'll make things a lot easier. So replace all that "set the string value of text field 5" business with this new method, which I'll detail in a bit.

Quote:
Where do i type in the stuff in the square brackets?
Those particular lines need to be after the "get window 1". So all in all it would look something like this:
Code:
tell application "ffmpegX"
	get window 1
	return the title of every button of the result
end tell
Quote:
1) Make the file to be converted be the file that i drop onto the script icon.
To make a droplet, there are two things you need to do:
1) Create an "on open {the_file}" statement, where the_file is the variable that will store the file that was dropped.
2) Save the script as an application.

Once we have the_file, we just open it with ffmpegX, like I mentioned before.
Code:
tell application "Finder"
	open (the_file) using application file ((the application file of application process "ffmpegX") as text)
end tell
I know that whole [application file ((the application file of application process "ffmpegX") as text)] looks nasty, and it is. I'm not sure WHY we have to coerce it to text and then back to 'application file', but...we do. Whatever works, right?

Another thing I should mention is that the "open" handler will only process ONE file. If you drag a bunch of files onto your icon, it won't process them all. There are some nasty ways around this, though. Take a look at some of Apple's examples, like "/Library/Scripts/ColorSync/Build profile info web page".

Quote:
2) Tell ffmpegX the settings for the target format. (I know you told me create a Preset format but i had trouble loading it)
I'm getting problems myself now, too. Ouch. I have NO problems when opening my presets manually. I'm not sure what the script is doing differently, but I think that's what we need to figure out.

You COULD enter all your settings by manipulating the buttons and stuff, the same way we dismissed the registration window and entered the file paths. Follow the general procedure I explained before, and you should be able to manually configure it. Buuuut, it'd be a big fat pain in the rear, to say the least. It takes a lot of trial-and-error poking around to get that kind of thing done, and ffmpegX has a LOT of interface elements to contend with. I'm scared just thinking about it.

I'm going to mess around with this later. There's gotta be a way to get it working. The code I have so far (which doesn't work sometimes) is this:
Code:
tell application "Finder"
	open file "Path:to:preset.ffx"
	open (the_file) using application file ((the application file of application process "ffmpegX") as text)
end tell
Edit: I just flipped those two lines, so that it'll load the preset AFTER it loads the movie, and now it seems to work. Does that work on your end, too?

Quote:
3) I need to do something about what the file will be saved as. I want the file to be saved to the desktop, but I don't want the file to be saved as XYZ.mov. I want each file to be saved as something else.
That's doable, too. It just depends on how you want to do it.

Do you want to use a standard Save dialog? If so, what you need is in Standard Additions, an AppleScript user's best friend. It's located at "/System/Library/ScriptingAdditions/StandardAdditions.osax". Drag it onto Script Editor and peek inside. In the "User interaction" section, you'll find everything you need. To get a standard Save dialog, use the "choose file name" function.

Also, using the new method I mentioned of loading the movie into ffmpegX, we'll get ffmpegX's automatic destination generation, which will be in the same folder as the source. If that's good enough for you, it'd save a lot of effort. Otherwise, use choose file name, and convert the result to a unix-style path using System Events, like we did before.
__________________
Mac mini — 1.25GHz G4, 1GB RAM — OS 10.5.2

I'm now a four-browser man. How on earth did this happen?!

Useful programs: PithHelmet, Butler, ffmpegX, VLC, Perian, Tofu, Wcalc

Last edited by Mikuro; October 23rd, 2005 at 02:00 PM.
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -5. The time now is 04:41 PM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.