This has been bugging me for awhile and I finally figured it out. Here’s how you can use Bash and AppleScript to get the file path to the current document selected in Xcode:
#!/bin/bash PATH=`osascript -e "tell application id \"com.apple.dt.Xcode\" to return path of text document 1 whose name ends with (word -1 of (get name of window 1))"` echo $PATH
Bam. Now you can use an Xcode behavior to run a bash script and do whatever you want with the file.
Hint: try running uncrustify to auto-format it:
uncrustify -f $PATH