XCode Project automation by Ruby script


Using my python script I solved 95% of my XCode modification problem. But there was one problem that doesn’t solve my python script. Modifying Xcode’s .plist bundle identifier by script doesn’t change the .xcodeproj file’s packing bundle identifier. Thus it need to modify the .xcodeproj file.

I found Ruby has and excellent active library xcodeproj which can easily solve my problem. To learn the basics of Ruby I used the reference from following site.

So here is my Ruby script to change PRODUCT BUNDLE IDENTIFIER for my .xcodeproj file. From my python script  I pass the directory path and the bundle id, and ruby script finish my job.

#!/usr/bin/ruby
#XCode modification

require 'xcodeproj'

bundleId = ARGV[0]
path = ARGV[1]

project_path = path + "/XCodeProject.xcodeproj"
puts(project_path)
project = Xcodeproj::Project.open(project_path)

app 	=  project.targets[0]
wkExApp =  project.targets[1]
wkApp   =  project.targets[2]

puts app.name
puts wkApp.name
puts wkExApp.name

app.build_configurations.each do |config|
	config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = bundleId
end

wkApp.build_configurations.each do |config|
	config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = bundleId + ".watchkitapp"
end

wkExApp.build_configurations.each do |config|
	config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = bundleId + ".watchkitapp.watchkitextension"
end

project::save()

To call ruby script from python script I run the following code.

def modifyXCodeProjByRuby(bundleIdentifier, path):
    print("XCode Project Modified by Ruby")
    rubyModifyCommand   = "ruby RUBY_FILE_NAME.rb " + "\"" + bundleIdentifier + "\"" + " " + "\"" + path + "\""
    print(rubyModifyCommand)
    os.system(rubyModifyCommand)
mahmud ahsan

Computer programmer and hobbyist photographer from Bangladesh, lives in Malaysia. My [Business | Twitter | Linkedin | Instagram | Flickr | 500px]

You may also like

LEAVE A COMMENT