Launching Applescript from within Flash: Newbie needs help!

Greetings!
I have a Flash MX movie that I want to do the following: When the user clicks a button, it launches a particular file in Adobe Acrobat Reader. The file will eventually be on a CD Rom that should be cross-platform. I’ve got the PC side figured out, but apparently the Mac side needs to use Applescript, with which I am not at all familiar. I have some tips from flashjester.com, which says to do the following:

the AppleScript and files should be in the same folder for the sake of simplicity.
The applescript must be saved as an application, set to ‘run only’, and with the extension visible. It is handy to keep the files in the ‘fscommand’ folder, so you must call it too:

tell application “Finder”
activate
select file “your_file.pdf” of folder “fscommand” of disk “Your_CD_image”
open selection
end tell

Save this as, for example, ‘your_applescript.app’

and the button code must read:

on (release) {
fscommand(“exec”, “your_applescript.app”);
}

I have done all this, but each time I try it, nothing happens. I believe I am doing everything right. I have my Flash projector file (not the .swf file) and I have the fscommand folder with the applescript inside. One thing I do not understand is the part about “and with the extension visible.” I know that my applescript script (saved as an action) is called “getpdfmac.” I think I called it “getpdfmac.app” but I don’t see the .app part. Is there some way to make extensions visible? For other files I see the extension, like “welcome.swf.” Maybe this is the problem–the extension is not visible? This is the only thing I can figure that I’m not sure I’m doing correctly.
If anyone can make any sense of this (it seems like a common issue), I would greatly appreciate the help. I’d be glad to ftp or email you the file so you can check it. If anyone has any ideas, please, please reply to this post or email me at emily@garman.com.

THANKS!!!
Emily[/b]

When you save your AppleScript as an Application (or whatever) there is a check box in the Save Dialog window named “Hide Extension”. Make sure it has a check mark in it when you want the extension to be shown.

When you save a script as “run only” you will never be able to edit, so try to keep an editable copy of your scripts by Not checking the “Run Only” box in the Save Dialog. That way you’ll have a copy that you can edit, if needed. I don’t have Flash so I can’t help much further, Good Luck Emily…

The only options I have on my “save as” dialog are:

Stay Open
Never Show Startup Screen
Require the Classic Environment

This is when I do “save as” AND “save as run-only.”

Do I need to upgrade or something? I’m getting desperate here…

Thanks!

Emily

hmmmm, there is an expansion button to the right of text area where you title your script from the “Save As” option. Try clicking it to see if you get more options, then you should see the “Hide Extension” check box.

Anyway, after you save the app, you can still switch to the Finder and get-info about the item, then take a look the “name and extension” part and see if the “hide extension” checkbox is checked (or not).

(also make sure you are testing your projector/swf file from the CD or a mirror image, so the applescript can find the disk “Your_CD_image”)

I am using OS10.2.6…maybe that is why? I know I need to upgrade to Panther. My Applescript says it’s version 1.9. Is there a newer one out there? If so, how would I get it?

JJ, I will try what you said about looking in the info box about the extensions. I am trying it from a disk image that is titled the same as what I call “mydisk” in the applescript. So I know that is not the problem.

One other thing that is weird is when I test the script in Applescript, using the “Run” command, it works! It launches the PDF just fine. It’s only when I do it from the CD Image that it doesn’t work. Does that give you all any more clues?

Thanks so much for your help. I really really hope you’ll stick with me here and help me figure this out!!

Emily

Update: I Checked in the Get info window on my file. The title of my actionscript is “getpdfmac” (for one thing, is that too long a title? Somewhere in my mind I think maybe it has to be 8 characters or less??). So I did “Save As Run-Only” and chose application. I entered the file name as “getpdfmac.app”.

Now when I go to “get info” and choose “name and extension” it says:
getpdfmac.app

in the window. Is that what it should say? I don’t see any options about turning on/off extensions, though, and I don’t see the extension in the regular Finder window, like I do for other files (like “welcome.swf” or something).

Does that help at all?

Thanks!!

Emily

At least in Panther, you can choose “Preferences” in the “Finder” menu, then in the “Advanced” tab choose “show all files extensions” (or whatever is labeled).
It shouldn’t be problems with the length of the name of your app but, if you don’t need long names, perhaps it’s better you use short ones.
Hmmm… So it still doesn’t work. If you “get info” over the original app and the one in the CD, they are the same size?

Well, thanks to the help of Brennan and all the rest of you on here, I was able to write a better script that actually worked! Here it is:

tell application “Finder”

open file “yourfile.pdf” of folder “fscommand” of disk “mydisk”

end tell

I got rid of some of that extra stuff in there.

NOW the problem is that this script will not work on anything other than OS X. I know some scripts are only compatible with OS X and vice versa…but this seems like such a simple script that it ought to work with all the OSs. I know that I will have users with all the different operating systems, and the script has to work on all of them. is there a better way to do this so it will work on versions 8.6 and up? Is that even possible?

You guys are my heroes!!! Thanks for all the help.

Emily

And even shorter :

tell application “Finder” to open file “yourfile.pdf” of folder “fscommand” of disk “mydisk”

or the shortest

tell app “Finder” to open file “nameOfDisc:directory:directory:file”

:wink:

For safety’s sake, you can create two versions (requires at least Flash 6):

if (System.capabilities.os.indexOf('10.') != -1) {
	fscommand("exec", "getpdfmacX.app"); // launch OS X version
} else {
	fscommand("exec", "getpdfmac.app"); // launch OS 8.6 thru 9.x version
}

Simply pick a OS 9 machine and compile a new version for OS 9 and back (or if you own a copy of Script Debugger, you can save a “classic” version from there).