• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Passing argumenst to C executable from Apple script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Passing argumenst to C executable from Apple script


  • Subject: Re: Passing argumenst to C executable from Apple script
  • From: Philip Aker <email@hidden>
  • Date: Mon, 16 Jun 2008 03:09:06 -0700

On 08-06-14, at 01:42, SVV Satyanarayana wrote:

do shell script "\"$(dirname " & quoted form of prefix & ")\" " & quoted form of POSIX path of arg1 & " " & quoted form of POSIX path of arg2

In the above example mentioned, if I want to pass "path of some file" as argument, I have to use "quoted form of POSIX path of arg 1"  etc.
But what if I want to pass some integer values or strings as an argument?


'do shell script' always takes a single string as input. Multiple arguments are normally separated by a space.

In AppleScript, to coerce an integer to a sting, you would write "99 as text".

On Mac OS X, it's not customary or even approved of to use a ".exe" extension for executable binaries (that's a Windows idiosyncracy). Unix tools normally don't have extensions to specify their kind. 

If your tool is located on the desktop then a script to call it from Script Editor might look like:

set tool_path to (path to desktop folder as text) & "MyTest"
set ppath to POSIX path of tool_path
set textnum to 99 as text
set command to (quoted form of ppath) & space & textnum
do shell script command



On 18-Apr-08, at 6:02 PM, Mark J. Reed wrote:
If it's named "MyTest.exe", then "./MyTest" won't work.  OS X is not Windows

How are you running the script?  I don't think you can safely assume
anything about the current working directory in AppleScript - you will
have to use "path to me" and friends to build an absolute path to
MyTest.

AppleScript has no access to execv*() directly; you have to go through
the shell.  Build a command line by concatenating the full path to
MyTest with the quoted forms of the arguments together into a string
separated by spaces, and then run that command line via "do shell
script".

Example:

set prefix to POSIX path of (path to me as alias)
set arg1 to choose file with prompt "first file"
set arg2 to choose file with prompt "second file"
do shell script "\"$(dirname " & quoted form of prefix & ")\" " &
quoted form of POSIX path of arg1 & " " & quoted form of POSIX path of
arg2

But Xcode has much better ways of accomplishing the goal of "prompt
the user for files and then run this C code on them".



On 4/18/08, SVV Satyanarayana <email@hidden> wrote:
I have directory "Test" which consists of MyScript.scpt (Apple script
file created from script editor) and an executable MyTest.exe
(compiled C program).
MyTest.exe takes two parameters as arguments. (Example to run it "./
MyTest name age")
MyScript.scpt must show a dialog to accept two parameters and when
user presses OK button, it must call my MyTest executable with
necessary data from script.

I think I gave clear description now.
please revert back if not clear.

SVV Satyanarayana
Bangalore, India


On 18-Apr-08, at 1:30 PM, Philip Aker wrote:

On 08-04-17, at 21:57, SVV Satyanarayana wrote:

From Apple script, I am showing a dialog with few textboxes and a
button. On click of the button, I want to call some "C" executable
with arguments as strings in textboxes. How can I do this?

To call command line tools, use the 'do shell script' command.
Details are in the Standard Additions dictionary.

It's not clear from your post whether or not you are in an
AppleScript Studio project and whether or not you are targeting a
tool or a scriptable application.
To target a scriptable application use the form:

tell application "System Events"
activate
set flist to path of every file of desktop folder whose visible is
true
choose from list flist
end tell

Philip Aker
echo email@hidden@nl | tr a-z@. p-za-o.@

Democracy: Two wolves and a sheep voting on lunch.

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Re: Passing argumenst to C executable from Apple script (From: SVV Satyanarayana <email@hidden>)

  • Prev by Date: Re: Running ruby (utilizing appscript) from do shell script
  • Next by Date: Applescript localization support
  • Previous by thread: Re: Passing argumenst to C executable from Apple script
  • Next by thread: Applescript localization support
  • Index(es):
    • Date
    • Thread