{"id":158,"date":"2009-03-09T08:39:16","date_gmt":"2009-03-09T13:39:16","guid":{"rendered":"http:\/\/www.jaimerios.com\/?p=158"},"modified":"2009-03-09T08:39:16","modified_gmt":"2009-03-09T13:39:16","slug":"perforce-xcode-and-scripts","status":"publish","type":"post","link":"https:\/\/jaimerios.com\/?p=158","title":{"rendered":"Xcode 3.1, Perforce and Scripts"},"content":{"rendered":"<p>In my previous post, I showed how you can leverage AppleScript to check out a file or a project that resides on a Perforce server. The reason for this is that Xcode 3.x does not work well with Perforce. <\/p>\n<p>Now, I figured out how to do this with the build in scripts menu in Xcode. The limitations I found so far is that you can only check out a file, can&#8217;t do a project yet, and that the cursor has to be in the file that you want to check out. <\/p>\n<p>So I created a script, named it &#8220;Check out file&#8221; and put it in a section named &#8220;Gravy&#8221; since that is what I work with most. The script code is:<\/p>\n<pre lang=\"bash\">\n#!\/bin\/sh\n# This shell script checks out the current file from Perforce, so long as it has the cursor in it\n\n# Get the file's full path\nFULL_FILE_PATH=\"%%%{PBXFilePath}%%%\"\n\n# Check to make sure it exists\nif [ -f \"$FULL_FILE_PATH\" ]\nthen\n\t# Separate the filename and the path\n\tSRC_FILE=${FULL_FILE_PATH##*\/}\n\tFILE_PATH=${FULL_FILE_PATH%\/*}\n\t\n\t# Go to the folder and invoke the p4 command line app with the appropriate arguments\n\tcd \"$FILE_PATH\"\n\t\/usr\/local\/bin\/p4 -cjrios_My_Perforce_ClientName -pperforce.jaimerios.com:1666 -PHah -ujaimer edit \"$SRC_FILE\"\n\n# This is a hack to get Xcode to recognize that the file was checked out\n# Notice that the code is not indented\nosascript - \"$1\" << ENDOFSCRIPT\ntell application \"Xcode\"\n\tset myFile to associated file name of front window\n\tsave myFile\nend tell\ntell application \"Finder\"\n\tactivate\nend tell\ntell application \"Xcode\"\n\tactivate\nend tell\nENDOFSCRIPT\n\t\nelse\n\techo File not found:\"$SRC_FILE\"\nfi\n<\/pre>\n<p>For the output and error options, I set them to \"Display in Alert\".<\/p>\n<p>And that's it. I hope this helps you and if you have any comments for improving this, post a comment and let me know.<\/p>\n<p>Happy coding!<\/p>\n<p>Reference:<br \/>\n<a href=\"http:\/\/developer.apple.com\/DOCUMENTATION\/DeveloperTools\/Conceptual\/XcodeWorkspace\/310-User_Scrips\/custom_scripts.html#\/\/apple_ref\/doc\/uid\/TP40002707-SW6\" target=\"_blank\" rel=\"noopener\">Xcode shell scripting<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my previous post, I showed how you can leverage AppleScript to check out a file or a project that resides on a Perforce server. The reason for this is that Xcode 3.x does not work well with Perforce. Now, I figured out how to do this with the build in scripts menu in Xcode. &#8230; <a title=\"Xcode 3.1, Perforce and Scripts\" class=\"read-more\" href=\"https:\/\/jaimerios.com\/?p=158\" aria-label=\"Read more about Xcode 3.1, Perforce and Scripts\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[349,397,506],"class_list":["post-158","post","type-post","status-publish","format-standard","hentry","category-coding","tag-perforce","tag-scripts","tag-xcode"],"_links":{"self":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=158"}],"version-history":[{"count":0,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/158\/revisions"}],"wp:attachment":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}