Solved

launch applescript programmatically from C++ program

Posted on 2004-09-23
5
1,106 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now