Re: Xcode 4 editor scripting - help!
Re: Xcode 4 editor scripting - help!
- Subject: Re: Xcode 4 editor scripting - help!
- From: Eric Wing <email@hidden>
- Date: Tue, 28 Feb 2012 01:27:09 -0800
> I'd like to hear more. I have yet to figure out how to do anything like
> replace the current selection. I've tried a bunch of different things in
> AppleScript, but I can't seem to get them to do anything except return
> errors. And I'm not married to AppleScript either - if I could do this in
> any script language, I'd be happy enough.
Here's a LuaCocoa script using Scripting Bridge and System Events
(because I'm not smart enough to figure out how to write in actual
AppleScript). This script is based off a real evil 500 line script I
presented at Silicon Valley Cocoaheads to automate the Xcode Organizer
for continuous integration and automated testing on iOS devices. I had
to resort to System Events because the Xcode 4 Scripting Bridge
dictionary is defunct.
#!/Library/Frameworks/LuaCocoa.framework/Versions/Current/Tools/luacocoa
LuaCocoa.import("ScriptingBridge")
local system_events =
SBApplication:applicationWithBundleIdentifier_("com.apple.systemevents")
local processes = system_events:processes()
local xcode_process = nil
for i=1, #processes do
-- print("processes[".. tostring(i) .. "]" .. processes[i]:name())
if tostring(processes[i]:name()) == "Xcode" then
xcode_process = processes[i]
end
end
if not xcode_process then
print("Could not find Xcode process running. Aborting...")
os.exit(1)
end
-- Bring the Xcode app to the foreground
xcode_process:setFrontmost_(true)
-- Type 'test'.
system_events:keystroke_using_("test", 0)
The script obviously needs LuaCocoa to run.
http://playcontrol.net/opensource/LuaCocoa
I just used the luacocoa command line tool that comes with it to
invoke this script from a terminal. Once the script launches, it looks
for the Xcode process and switches it to the foreground. It assumes
your text was already highlighted and then just starts typing 'test'.
I'm sure there are much more clever ways to invoke it.
-Eric
--
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/
_______________________________________________
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