{"id":136,"date":"2009-03-07T09:36:06","date_gmt":"2009-03-07T14:36:06","guid":{"rendered":"http:\/\/www.jaimerios.com\/?p=136"},"modified":"2009-03-07T09:36:06","modified_gmt":"2009-03-07T14:36:06","slug":"xcode-31-and-perforce","status":"publish","type":"post","link":"https:\/\/jaimerios.com\/?p=136","title":{"rendered":"Xcode 3.1 and Perforce"},"content":{"rendered":"<p>I use Perforce and I love it! Over the years I&#8217;ve used Visual SourceSafe, CVS, SVN and I experimented with other tools, but none of them have come close to the usefulness of Perforce.<\/p>\n<p>I also use Xcode for my Mac coding but when you use Xcode with Perforce, you get some wierd behaviour. Xcode get&#8217;s hung, for no reason whatsoever and although Apple seems to know this is a problem, it doesn&#8217;t seem like they are fixing this problem any time soon. <\/p>\n<p>Lucky for me you can use AppleScript from within Xcode! I usually work on one project at a time, so I can create an AppleScript that checks out the frontmost project file for me and another AppleScript to check out the currently selected source code file. <\/p>\n<p>When you open Xcode you&#8217;ll notice an AppleScript icon in the menubar between Window and Help, but this is not an AppleScript drop down. This is just for the General Scripts that can be invoked from Xcode. So, if you want to run a shell script from Xcode, you can use this scripts menu for doing that, but for me, I wanted to leverage AppleScript for what I want to do. <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jaimerios.com\/wp-content\/uploads\/2009\/03\/scriptmenu-150x150.png\" alt=\"You think this is for AppleScript, but it&#039;s not.\" title=\"Script menu\" width=\"150\" height=\"150\" class=\"size-thumbnail wp-image-142\" \/><\/p>\n<p>So, to make the AppleScript menu available, you have to open the AppleScript Utility in &#8220;\/Applications\/AppleScript\/&#8221;. Open that program and click the &#8220;Show Script menu in menu bar&#8221; checkbox.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jaimerios.com\/wp-content\/uploads\/2009\/03\/applescriptutility-150x150.png\" alt=\"Use this to make the Script menu available\" title=\"AppleScript Utility\" width=\"150\" height=\"150\" class=\"size-thumbnail wp-image-141\" \/><\/p>\n<p>Once you do that, you should see an AppleScript menu item by the other icons on the left side of your menubar.<\/p>\n<p>Now, open the &#8220;Script Editor&#8221; program within the &#8220;\/Applications\/AppleScript&#8221; folder. Copy the code below, which attempts to check out the frontmost project file from Perforce:<\/p>\n<pre lang=\"AppleScript\">\n-- Check out the frontmost project\ntell application \"Xcode\"\nset myProj to (active project document)\nset myCmd to full path of myProj\nend tell\n\nset myCmd to \"\/usr\/local\/bin\/p4 -cjrios_My_Perforce_ClientName -pperforce.jaimerios.com:1666 -PHah -ujaimer edit \" & myCmd & \"\/...\"\n\ndo shell script myCmd\n<\/pre>\n<p>Basically, the script gets the frontmost project file, sets a variable to the full path to the project file and then I create a string with the command that I would normally invoke in Terminal.app. The changes you need to make to the command line are:<\/p>\n<ul>\n<li>The -c option which tells p4 which client you are working in<\/li>\n<li>The -p option which is the name, or ip, with TCP port to the perforce server<\/li>\n<li>The -P option which is your password to the server and<\/li>\n<li>The -u option which is your username<\/li>\n<\/ul>\n<p>Notice that I don&#8217;t have a space between the switch and the value and that I have the full path to p4 spelled out.<\/p>\n<p>Paste the code into a new script in &#8220;Script Editor&#8221; and save the script, with the name of your choice, into the &#8220;\/Users\/jaimerios\/Library\/Scripts\/Applications\/Xcode&#8221; folder. Once you go back to Xcode, you will see your script in the menu item.<\/p>\n<p>Now the following script is almost the same thing, except for it checks out the current file that is selected in the project. Repeat the same steps for creating the project check out script for the script code below:<\/p>\n<pre lang=\"AppleScript\">\n-- Check out the currently selected file\ntell application \"Xcode\"\n\nset myFile to associated file name of front window\nset textDocuments to text documents\nrepeat with i in textDocuments\nif path of i is myFile then\n\nset myCmd to path of i\nset myCmd to \"\/usr\/local\/bin\/p4 -cjrios_My_Perforce_ClientName -pperforce.jaimerios.com:1666 -PHah -ujaimer edit \" & myCmd\ndo shell script myCmd\nend if\nend repeat\n\nend tell\n\n<\/pre>\n<p>I hope these scripts help you out. If you have any suggestions for making these scripts better, post a comment and let me know.<\/p>\n<p>Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I use Perforce and I love it! Over the years I&#8217;ve used Visual SourceSafe, CVS, SVN and I experimented with other tools, but none of them have come close to the usefulness of Perforce. I also use Xcode for my Mac coding but when you use Xcode with Perforce, you get some wierd behaviour. Xcode &#8230; <a title=\"Xcode 3.1 and Perforce\" class=\"read-more\" href=\"https:\/\/jaimerios.com\/?p=136\" aria-label=\"Read more about Xcode 3.1 and Perforce\">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":[340,349,506],"class_list":["post-136","post","type-post","status-publish","format-standard","hentry","category-coding","tag-p4","tag-perforce","tag-xcode"],"_links":{"self":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/136","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=136"}],"version-history":[{"count":0,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/136\/revisions"}],"wp:attachment":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}