Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jodagee

macrumors newbie
Original poster
Apr 11, 2014
2
0
Hi Guys,

I'm relatively new to applescript but I'm quick at exploring and getting up to speed with things. I have been experimenting and was wondering whether it was possible to define commands at runtime?

For example you could code:
tell application definedApplication to make new folder ....
where definedApplication was entered to a dialog at runtime.

Is it possible to do the opposite and instead of defining the name of the application at runtime, define the command to be used, i.e.:
tell application "Finder" to liveCommand
where liveCommand is entered via a dialog?

Thanks for your time :)
 
You can send variable commands to an application, but you need to specify an application for a command. In some cases application scripting terms may be similar, but in general AppleScript needs to know what the target application is so that it can use its scripting dictionary.

An alternative would be a completely constructed application tell statement - this is frequently used with osascript or NSAppleScript in Cocoa applications, for example.
 
You can send variable commands to an application, but you need to specify an application for a command. In some cases application scripting terms may be similar, but in general AppleScript needs to know what the target application is so that it can use its scripting dictionary.

An alternative would be a completely constructed application tell statement - this is frequently used with osascript or NSAppleScript in Cocoa applications, for example.

Could you give an example about how to do this in applescript? Everything I put a command even in quotes it prevents it from working. Cocoa is objective c right? I've tried learning that, but I don't even know where to begin! Thanks :)
 
Could you give an example about how to do this in applescript? Everything I put a command even in quotes it prevents it from working. Cocoa is objective c right? I've tried learning that, but I don't even know where to begin! Thanks :)

Post your code that doesn't work. Use CODE tags.

Also post the exact text of error messages (copy and paste; don't paraphrase).

Identify your OS version.
 
Could you give an example about how to do this in applescript? Everything I put a command even in quotes it prevents it from working. Cocoa is objective c right? I've tried learning that, but I don't even know where to begin! Thanks :)

Cocoa is usually accessed with Objective-C, but it can also be used via AppleScriptObj-C in a Cocoa-AppleScript. Using a shell script to run an AppleScript inside an AppleScript is a bit redundant, but osascript can be useful to run small self-contained scripts, and is often used from other languages such as Ruby or Python. The quoting part is the trickiest, just remember to escape any quotes you are using inside a string, since those are normally used to delimit the string. A simple example would be something like:

Code:
set theFile to (choose file) as text

set theScript to "tell application \"Finder\" to get the name of file \"" & theFile & "\""
set theName to do shell script "osascript -e " & quoted form of theScript
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.