Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Writing applescripts in Windows XP that are executable in OS X

Hi. I'm working on some software that involves generating scripts on Windows XP for OS X to run.

Is it possible to create applescript files in Windows XP, and to have them be executable in OS X straight from Windows?

By executable, I mean that the user can just double-click on the file icon, and have the script run.

Thanks for any help.

-Bassam

Macbook Pro Mac OS X (10.4.6) Recently switched from Windows XP

Macbook Pro Mac OS X (10.4.6) Recently switched from Windows XP

Posted on Sep 14, 2006 4:56 PM

Reply
10 replies

Sep 16, 2006 7:53 AM in response to Gnarlodious

Sort of extending what Gnarlodious and reese said...

You could probably generate a text file on the Windows side that was essentially a shell script that used "osascript" to execute AppleScript on the Mac. The osascript command could execute another text file containing AppleScript source (it will compile and execute this on the fly), or a pre-compiled AppleScript (which would have to be compiled on the Mac beforehand) or you could even specify the AppleScript source text inline within the shell script (using osascript's "-e" option). See "man osascript" for more details on how it works.

The shell script would kick off Terminal on the Mac (which might be a problem), but if the shell script was given a ".command" extension it would be double-clickable in the Finder.

Another issue you'd have to deal with is getting the executable flag set on the shell script once it was transferred to the Mac.

So it wouldn't be totally seamless but it's an option you might want to think about.

Steve

Sep 18, 2006 2:19 PM in response to Steve Herman1

Hi Steve,

How do you make a shell script double-clickable?
It would be a good solution, but I've tried just adding the .command to a script, but double-clicking it in OS X just opens it up in TextEdit, and doesn' run it. I am able to run the test script in Terminal, so I know that it works.

Thanks.

Macbook Pro Mac OS X (10.4.6) Recently switched from Windows XP

Sep 18, 2006 3:25 PM in response to Bassam Islam

Bassam,

You've got the shell script file's executable bits set right? Since you can run it in Terminal I would guess that you must.

Normally all you have to do is rename a file so that it's extension is ".command". As far as I know Terminal is the default app that open's files with a .command extension, but that could have gotten changed on your machine.

Try doing a Get Info on your file and check the "Name & Extension". Is it possible that you've got the file named with two extensions like "MyFile.command.txt" and the ".txt" part is hidden? That certainly might trigger TextEdit to open your file.

If the file name looks correct then check the "Open With" setting (also in the Get Info window). Is that set to TextEdit? If so, then switch the pop-up so it says "Terminal". And you may want to click the "Change All..." button so all of your .command files will run in Terminal.

Steve

Sep 18, 2006 6:09 PM in response to Steve Herman1

Steve,

I have checked the Get Info, and there is not .txt in the file name that's hidden.

Looking at the open with, it does have TextEdit as a default, and Terminal is an option, though I don't know if that's because Finder remembers me manually selecting Terminal in the Open With dialog.

The thing is that this script will be going out to machines that I don't have control over, so I would want the script files to be double-clickable as delivered, and not require any changing of the default handling program.

Are .command files always associated with the Terminal by default?

Macbook Pro Mac OS X (10.4.6) Recently switched from Windows XP

Sep 18, 2006 7:18 PM in response to Bassam Islam

Hi,

You could also distribute a script app which runs the text script in the same folder. The script app might look something like this:

set my_path to (path to me as string)
set user_tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set temp_list to text items of my_path
set last item of temp_list to "script.txt"
try
set script_ref to (temp_list as string) as alias
set AppleScript's text item delimiters to user_tid
on error err_mess
set AppleScript's text item delimiters to user_tid
display dialog err_mess buttons {"OK"} default button "OK"
return
end try
run script script_ref

It gets a reference to the text file "script.txt" and runs the statments of text. If the file "script.text" doesn't exist in the same folder as the script app, then the script will display the error message and quit.

gl,

Sep 19, 2006 6:15 AM in response to Bassam Islam

The thing is that this script will be going out to
machines that I don't have control over, so I would
want the script files to be double-clickable as
delivered, and not require any changing of the
default handling program.


I don't think this would normally be an issue. But since it happened to you I understand your concern. Maybe distributing a .command file is not the best solution for your environment.

Are .command files always associated with the
Terminal by default?


As far as I know, yes, .command files are associated with Terminal by default. I'm not sure how your's may have gotten changed. I tried selecting a .command file in Finder and then both "File -> Open with... -> TextEdit" and <Control>-Click -> Open with... TextEdit. In both instances the file opened with TextEdit but it did not change the association to Terminal. Double-clicking the file after editing in TextEdit still launched Terminal.

On the other hand if you did a Get Info and changed the "Open with:" pop-up then it will change the association for future accesses to the file.

Steve

Sep 19, 2006 3:02 PM in response to Steve Herman1

Well, we've decided that having the user change the association of .command files if they are not associated with the Terminal is an acceptable level of complexity.

We're going to include instructions on how to do that in our installation documentation. Since you'd only have to do it the first time, if it's even necessary, it's not too complicated a solution.

Thanks everyone, especially Steve, for all your help.

Writing applescripts in Windows XP that are executable in OS X

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.