Setting the active project in Xcode

Hello I’m new to applescript and am having trouble changing the active project in Xcode.

In xCode the application has a property called “active project document” but I can’t figure out how to change this property. Is it possible to change this property? here is the the code I have so far the “???” is where I would change the property.


setActiveProject("ogsPing")

on setActiveProject(projectName)
	tell application "Xcode"
		
		set allProjects to project documents
		
		repeat with i in allProjects			
			set theProject to project of i
			set theProjectName to name of theProject
						
			if theProjectName = projectName then ???
			
		end repeat
		
		return active project document
	end tell
	
	
end setActiveProject

I’ve made the script simpler. It doesn’t need a loop, however I still can’t figure out how to set the active project document.


return setActiveProject("ogsPing")


on setActiveProject(projectName)
	set fullProjectName to projectName & ".xcodeproj"
	
	tell application "Xcode"
		set projRef to project document fullProjectName
		-- How can I make the line below work
		-- set active project document to projRef
	end tell
	
end setActiveProject

This will bring the specified project to the front making it the active project.

I set this up on Leopard. If you are using Tiger the menu item line may be
slightly different.


set xcodeProj to "MyProj.xcodeproj"

activate application "Xcode"
tell application "System Events"
	tell process "Xcode"
		click menu item xcodeProj of menu 1 of menu bar item "Window" of menu bar 1
	end tell
end tell

Regards,

Craig

Thanks for the workaround Craig. I’d still like to know why I can’t modify the property though, programmers curiosity.