Re: AppleScript in a Run Script Build Phase & User Interaction
Re: AppleScript in a Run Script Build Phase & User Interaction
- Subject: Re: AppleScript in a Run Script Build Phase & User Interaction
- From: Eric Gorr <email@hidden>
- Date: Tue, 24 Nov 2009 11:42:09 -0500
On Nov 24, 2009, at 11:29 AM, Chris Espinosa wrote:
>
> On Nov 24, 2009, at 8:20 AM, Eric Gorr wrote:
>
>> I have an AppleScript that I would like to have executed during a Run Script build phase. This AppleScript contains the line:
>>
>> set dialogResult to display dialog "Name to use:" default answer "MyName"
>>
>> For the build phase, I am currently using /bin/sh as the shell and the script is simply:
>>
>> osascript $SRCROOT/CreateUserFiles
>>
>> When I run the script, I get the error message:
>>
>> /Volumes/Depot/EricGsMainWS/Engineering/VectorWorks/TaskBranches/VW16/Cocoa/AppSource/CreateUserFiles:865:955: execution error: No user interaction allowed. (-1713)
>>
>> Is there a way to have user interaction during a Run Script Build Phase using AppleScript?
>>
>> If not, perhaps with another scripting language?
>
> Xcode executes Run Script build phases in a subtask that does not have a window server connection, which is why you're getting that error. To do user interaction, you have to message an app that can present UI, such as the Finder or System Events.
>
> Just wrap that line in a 'tell app "Finder"'/'end tell' block.
For those who are interested, the complete answer appears to be:
tell app "Finder"
activate
set dialogResult to display dialog "Name to use:" default answer "MyName"
set fixedUserName to text returned of dialogResult
end tell
tell app "Xcode"
activate
end tell
Using 'activate' makes sure the dialog does not appear behind Xcode.
btw, is there a way to place the AppleScript directly in the Run Script Build Phase and avoid using osascript?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden