Solved

launch applescript programmatically from C++ program

Posted on 2004-09-23
5
1,138 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Importing Special Characters in Dynamics GP Through Integration Manager 3 89
countEvens challenge 2 114
wordmultiple challenge 12 156
Message not shown 5 85
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

733 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