 |
 |
pass variable from C to Applescript?
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Aug 2002
Status:
Offline
|
|
Hi all,
I'm trying to pass a variable from some standard C code to an Applescript but i can't get it to work.
I have a variable called "buf" and want to display it in a finder alert.
this c code works:
Code:
printf("buffer contains: %s", buf);
Here is the snippet that doesn't work:
Code:
system("osascript -e 'tell application \"Finder\"
display dialog \"buffer contains: \" & buf & \" \"
end tell'");
The is the error i get: "execution error: The variable buf is not defined. (-2753)"
I appreciate any help
Cocoaholic
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 2001
Location: ~/
Status:
Offline
|
|
Osascript is running the Applescript element of your program, not the program itself. To osascript buf does not exist anywhere. As of yet osascript does not allow you to pass arguments into a script which is what you would need to do in order to have this whole thing work properly.
If you want to use the AppKit framework from an app without using Interface Builder and all that jazz it is possible. Encapsulate your C code inside a cheapo Obj-C wrapper and you can display all kinds of cool stuff in a window.
Start here for building C-callable wrappers to Cocoa objects http://developer.apple.com/techpubs/...Functions.html.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Aug 2002
Status:
Offline
|
|
Thanks, i'll see if i can figure out how to use this.
I'm not a real programmer, just trying to code
Are there any code samples out there using this technique?
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 2002
Status:
Offline
|
|
Try this:
Code:
const char *command = "osascript -e 'tell application \"Finder\"\ndisplay dialog \"buffer contains: ";
strcat(command, buf);
strcat(command, "\"\nend tell'");
system(command);
The general idea here is to first build up the command in your program, which has access to buf, and then pass the whole thing to osascript.
|
|
[vash:~] banana% killall killall
Terminated
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Aug 2002
Status:
Offline
|
|
Thank you, i was looking for something like that! (i saw a similar perl example)
It didn't work for me though, had to change it to:
Code:
char command[256] = "osascript -e 'tell application \"Finder\"\ndisplay dialog \"buffer contains: ";
strcat(command, buf);
strcat(command, "\"\nend tell'");
system(command);
I have a very basic server (unix tool) which listens for incoming data, when it receives the right commands it has to open a cocoa application and pass the received data to that app.
I could do this by making this cocoa app Applescriptable but maybe this C-callable wrapper stuff would be better/easier?
Maybe there is a even better way?
Cocoaholic
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |