Solved

launch applescript programmatically from C++ program

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET how to use the Vertical ScrollBar 5 90
Expand macro to include alternate header placement and naming 5 66
Whole sheet autoscrub still needed 19 48
java ^ examples 8 62
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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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 is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

895 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

18 Experts available now in Live!

Get 1:1 Help Now