Skip to content
Browse files

Better Xcode4 integration via Pre-actions

  • Loading branch information...
1 parent 6a22eb9 commit 061409183241e654adfb8e289f5bb316a6ce7593 @holtwick committed Aug 11, 2011
Showing with 89 additions and 52 deletions.
  1. +14 −9 README.md
  2. BIN website/xcode4scheme.png
  3. +75 −43 xobjc4.py
View
23 README.md
@@ -1,6 +1,8 @@
xobjc
=====
+**FULL XCODE4 COMPATIBILITY***
+
**Xcode4 Demo on YouTube [youtube.com/watch?v=Mzfv-ANydW4](http://www.youtube.com/watch?v=Mzfv-ANydW4).**
**XCode3 Demo on mov.io [mov.io/fE](http://mov.io/fE).**
@@ -80,6 +82,18 @@ Some pictures say more than thousand words. Here is a before/after diff showing
![Module](https://github.com/holtwick/xobjc/raw/master/website/demo-m.png "Module")
+XCode4 Integration
+------------------
+
+Edit your projects 'Scheme' and add a new 'Run Script Action' to your 'Build / Pre-actions'.
+Fill in the full path of your xobjc4.py. Now each time you build your project this script
+will be run. This is super handy.
+
+![Header](https://github.com/holtwick/xobjc/raw/master/website/xcode4scheme.png "Xcode4 Scheme Modifications")
+
+If Growl is installed it will also issue a notification.
+
+
XCode3 Integration
------------------
@@ -88,15 +102,6 @@ entry and copy and paste the contents of the file ``xobjc.py`` into the text fie
you are done. Just call the script form the menu or via the key shortcut you defined while you
are in the header or implementation file you like to become updated.
-XCode4 Integration
-------------------
-
-Copy `XObjC4.workflow` to `~/Library/Services/`. Now edit the workflow with `Automator` and
-adjust the path to `xobjc4.py`. You can now add a keyboard shortcut to it via the Keyboard settings
-in the System Preferences tool. In XCode4 you can call it via the `Services` menu or via your keyboard shortcut.
-
-If Growl is installed it will issue also a notification.
-
Related
-------
View
BIN website/xcode4scheme.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
118 xobjc4.py
@@ -612,53 +612,85 @@ def xcodeReload():
# print "XCode refresh"
# subprocess.call(['arch', '-i386', 'osascript', '-e', 'activate application "Finder"\nactivate application "XCode"'])
pass
+
+def callAppleScript(script, input=None):
+ import StringIO
+ if not input:
+ return subprocess.check_output(
+ ['osascript', '-e', script],
+ stderr=subprocess.STDOUT)
+
+ p = subprocess.Popen(['osascript', '-e', script], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
+ p.stdin.write(input)
+ ret = p.communicate()[0]
+ p.stdin.close()
+ return ret
+
+def callGrowl(msg):
+ callAppleScript("""
+ tell application "GrowlHelperApp"
+ set the allNotificationsList to {"XObjC"}
+ set the enabledNotificationsList to {"XObjC"}
+ register as application "XObjC" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "XCode"
+ notify with name "XObjC" title "XCode" description "%s" application name "XObjC"
+ end tell
+ """ % repr(msg)[1:-1])
+
+OUT = []
+
+def out(*a):
+ OUT.append(" ".join([str(v) for v in a]))
+
+def main():
+ filenames = callAppleScript("""
+ tell application id "com.apple.dt.Xcode"
+ return path of source documents
+ end tell
+ """)
+
+ if not filenames:
+ print "Nothing to do"
-if __name__ == "__main__":
- import sys
- import glob
+ filenames = [n.strip() for n in filenames.split(',')]
- # You can also place it into 'XCode User Scripts' but it does not relead the window yet
- try:
- filename = '%%%{PBXFilePath}%%%'
- except:
- filename = ''
+ modified = False
+ for filename in filenames:
- if filename and (not filename.startswith('%')):
- modifyFiles(filename)
- xcodeReload()
-
- elif len(sys.argv) >= 2:
- # srcroot = os.environ.get("SRCROOT")
+ filename = os.path.abspath(filename)
+ # print "Analyze %s" % filename
- modified = False
- for filename in sys.argv[1:]:
+ mfiles = [filename]
- filename = os.path.abspath(filename)
- # print "Analyze %s" % filename
-
- mfiles = [filename]
- if os.path.isdir(filename):
- for root, dirs, files in os.walk(filename):
- for name in files:
- if (BACKUP_FOLDER not in root) and name.endswith(".m"):
- mfiles.append(os.path.join(root, name))
+ # XXX Obsolete?
+ if os.path.isdir(filename):
+ for root, dirs, files in os.walk(filename):
+ for name in files:
+ if (BACKUP_FOLDER not in root) and name.endswith(".m"):
+ mfiles.append(os.path.join(root, name))
+
+ # print "FILES:"
+ # print "\n".join(mfiles)
- # print "\n".join(mfiles)
-
- # elif srcroot:
- # files = glob.glob("Classes/*.m")
-
- if mfiles:
-
- for fn in mfiles:
- if modifyFiles(fn):
- print "Modified %r" % fn
- modified = True
-
- if modified:
- xcodeReload()
- else:
- print "No modifications needed"
-
+ # elif srcroot:
+ # files = glob.glob("Classes/*.m")
+
+ if mfiles:
+
+ for fn in mfiles:
+ if modifyFiles(fn):
+ out("Modified: %s" % os.path.basename(fn))
+ modified = True
+
+ if modified:
+ # xcodeReload()
+ pass
else:
- print "Usage: xobjc.py [file/folder paths]"
+ out("No modifications needed")
+
+ s = '\n'.join(OUT)
+ if s:
+ print s
+ callGrowl(s)
+
+if __name__ == "__main__":
+ main()

0 comments on commit 0614091

Please sign in to comment.
Something went wrong with that request. Please try again.