• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Xcode 4 editor scripting - help!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re: Xcode 4 editor scripting - help! (From: Brad Oliver <email@hidden>)

  • Prev by Date: ld: illegal text-relocoation (direct reference) to (global, weak) error
  • Next by Date: Re: Missing libstdc++ symlink in the 10.6 SDK from Xcode 4.3?
  • Previous by thread: Re: Xcode 4 editor scripting - help!
  • Next by thread: Re: Xcode 4 editor scripting - help!
  • Index(es):
    • Date
    • Thread