views:

539

answers:

6

I have a user script that would be much more useful if it could dynamically change some of its execution dependent on what the user wanted. Passing simple switches would easily solve this problem but I don't see any way to do it.

I also tried embedding a keyword in the script name, but Xcode copies the script to a guid-looking filename before execution, so that won't work either.

So does anyone know of a way to call a user script with some sort of argument? (other that the normal %%%var%%% variables)

Thanks!

EDIT: User scripts are accessible via the script menu in Xcode's menubar (between the Window and Help menus). My question is not about "run script" build phase scripts. My apologies for leaving that somewhat ambiguous.

A: 
vt
A: 

User scripts are accessible via the script menu in Xcode's menubar (between the Window and Help menus). Wasn't sure what else to call them. What I'm asking about are not "run script" build phase scripts.

MyztikJenz
A: 

I suppose you could do something like this:

#!/bin/bash
result=$( osascript << END
tell app "System Events"
  set a to display dialog "What shall be the result?" default answer ""
end tell
return text returned of a
END
)
# do stuff with $result
vt
A: 

You can't pass parameters to user scripts — instead, user scripts operate on the context you're working in (e.g. the selected file, the selected text, etc.).

You should use the context to determine what the user really wants.

Chris Hanson
A: 

vt: While that could work, using applescript is ugly at best. Asking the user "Do you want to log the address or the description?" every single time makes using the script a pain. Thanks for offering it as a suggestion though.

Chris: That's what I was afraid of. Unfortunately, the context of the selection won't tell me if the user wants to log the address of an object vs the object's description as both are perfectly valid types of output.

I guess what I'm left with is making multiple copies of the script with different configurations or telling the user how to edit the script.

MyztikJenz
A: 

There are built in utility scripts that allow you to prompt the user and capture the reply.

You could prompt for a string, for example, then based on that perform a certain task.

The String prompt is:

STRING = `%%%{PBXUtilityScriptsPath}%%%/AskUserForStringDialog "DefaultString" "DefaultWindowName"`

If you notice, you're just calling an applescript they wrote using a static path. You could write your own applescript dialog and place it there if you want and bypass the need for cumbersome osascript syntax. There are others (for files, folders, applications, etc)

User Scripts Documenation

jkyle