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
Solved

launch applescript programmatically from C++ program

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand macro to ask for filename column 8 37
method notes when mouse over in eclipse 5 87
mapBully challenge 6 152
I could not set window to top 4 20
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: 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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

856 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