Solved

launch applescript programmatically from C++ program

Posted on 2004-09-23
5
1,122 Views
Last Modified: 2013-12-26
Hi,

I want to know how to launch an applescript programmatically from within C++ program
I use codewarrior.

Thank you,

BT
0
Comment
Question by:bachra04
  • 3
  • 2
5 Comments
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 12138775
You could always do:

      system("/usr/bin/osascript myAppleScript");

0
 
LVL 2

Author Comment

by:bachra04
ID: 12174189
I tried it but it seems not functionning
0
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 12175852
How is it not functioning?
Does it not find the script?  Did you supply the full path to the applescript?
Have you tried running it from the command line, using the above command?
Have you debugged the applescript itself?


0
 
LVL 2

Author Comment

by:bachra04
ID: 12180678
The script works correctly (it launches another application) and I tried that from the command line.
I also tried to change the location of the applescript but I didn't succeed to run it from the program.
I work under OS X can you please :
I put teh applescript directly under Macintosh HD

I tried teh following combinations:
 system("/usr/bin/osascript /Macintosh HD/myAppleScript");
 system("/usr/bin/osascript Macintosh HD/myAppleScript");
 system("/usr/bin/osascript :Macintosh HD:myAppleScript");
system("/usr/bin/osascript Macintosh HD:myAppleScript");

but the program failed to launch the script.
0
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 125 total points
ID: 12181460
> I put teh applescript directly under Macintosh HD

Littering the root directory with non-system related stuff is not a good idea.
(Aside from the fact that you require administrator access to write to the root.)

You should put the script inside the app-wrapper of the application you are building.
This is the Mac OS X way - fully self-contained application objects.
Checkout the Core Foundation CFBundle APIs (specifically CopyExecutableURL) or
leverage argv[0] passed to main(), which contains the pathname of you executable
program.


> I tried the following combinations: ...

None of those would be valid.  When using command line applications, whitespace is
considered a delimiter between arguments.  The space between "Macintosh" and "HD"
makes the osascript command think it is being supplied two separate scripts to execute.
The space needs to be quoted: either individually with backslashes, or by enclosing the
entire argument in quotes:
      system("/usr/bin/osascript \"/path with spaces/myAppleScript\"");

You also have to consider that when running commands via system(), you are invoking
the Unix shell to execute your program.   The Unix environment does not understand
Classic MacOS style paths (VolumeName and colon delimiters).  Unix pathnames start
at the root (/) and descend from there.  If "Macintosh HD" is the root volume, then
"/myAppleScript" would have been sufficient (aside from my earlier advice regarding
polluting the root directory).  If the program is on a different volume, all mounted
volumes are located under the /Volumes directory (including "Macintosh HD"), so
"/Volumes/Machintosh HD/myAppleScript" would be the volume-independent full path
to the script.

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
modThree challenge 4 90
Unix Command -- Challenging  question 7 90
Problem to open Excel file 15 133
Problem to App source 6 40
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question