TweetFollow Us on Twitter

Xcode Menu Scripts

Volume Number: 23 (2007)
Issue Number: 01
Column Tag: Scripting

Xcode Menu Scripts

Creating and installing Xcode menu scripts

By Jose R.C. Cruz

Introduction

Xcode is the de facto development environment for the MacOS X platform. Its Interface Builder allows user interfaces to be easily built and linked to the appropriate code. Its use of GCC enables it to support various languages, even exotic ones such as Haskell. Also, its build phase system is much easier to understand and maintain than the more kitchen-sink approach of makefiles.

Another unique feature of Xcode is its Script menu. It allows developers to add scripts that will customize or enhance the Xcode environment. These scripts can perform specific tasks on a selected text or file, or even on the entire project. They can also enable Xcode to interact with other third-party tools.

This article will focus on what constitutes an Xcode menu script. It will demonstrate how to use Xcode to write and install a menu script. It will also provide a number of script examples that developers may find useful. Readers are assumed to have a working knowledge of writing basic shell scripts.

To complement this article, the installer package, XcodeMenu, is available for download from the MacTech website. The package contains the project and file templates that will help readers write their own menu scripts. It also contains the example scripts shown in this article, as well as the Xcode project used to create them. The package can be downloaded at the following URL: ftp://ftp.mactech.com/src/mactech/volume23_2007/23.01/sit.

The Xcode Menu Script System

The Script menu is the central launch point for all Xcode menu scripts. Each item on the menu corresponds to a script stored inside the Xcode script directory. The directory itself is located on the OS X boot volume at the following path: /Library/Application Support/Apple/Developer Tools/Scripts/10-User Scripts.

Figure 1 shows the structure of the Xcode script directory, and its default contents. Notice that the 10-User Scripts directory is further subdivided into 6 other subdirectories. Each subdirectory gathers the scripts in terms of their general function. For instance, the 20-Search subdirectory contains those scripts that perform a search function.


Figure 1. The Xcode script directory.

The numbers before the names of each subdirectory and script show their positions on the Script menu. Each subdirectory is displayed as a submenu of that menu. A menu separator is defined using an empty file whose name consists of a number followed by three dashes. For instance, an empty file with a name of 15— in the subdirectory 50-Text places a menu separator between the scripts 10-sort.sh and 20-uniq.sh.

Anatomy of a menu script

In many ways, an Xcode menu script is similar to a basic shell script. Both are text files, and both can be written in any one of the popular shell languages such as sh, bash, and Perl. However, a shell script is usually stored as an ASCII text file. It usually receives its input from stdin, and sends its output to stdout. On the other hand, an Xcode menu script is stored as a UTF-8 text file. It often receives its input from the active source file. Where it sends its output will depend on how the script is configured.

Figure 2 shows the basic structure of a typical Xcode menu script. Like the shell script, it starts with a declarative header, also known as the she-bang. This header indicates the command-line tool that will interpret and execute the script. It is also used to pass command-line options to the tool. Make sure to check that the tool is correctly installed on the MacOS X platform. Otherwise, Xcode will return an NSTask error message stating the absence of the tool. It will also terminate the execution of the rest of the script.

For example, if the declarative header reads as #!/bin/bash, the bash tool will execute the menu script. If it reads as #!/usr/bin/python -t, the python tool will execute the script. The tool will also display warning messages for any inconsistent tabs present in the script.


Figure 2. Structure of a basic menu script (sort.sh).

Right after the declarative header is the arguments list. This list defines the input source for the script as well as its output destination. Also, it is where the script is assigned with a menu name and a shortcut key.

Finally, the last part of the script is the script body. This body consists of one or more command statements that will perform the specified menu action. The commands used by these statements depend largely on the command-line tool chosen for the task. Consult your tool's user manual for more information about its commands.

Known shortcomings

A number of issues limit the capabilities of an Xcode menu script. The most notable one is that the Script menu is enabled only if a source file has been selected. Otherwise, it is disabled even in the presence of an active Xcode project. This behavior prevents a script from performing project-oriented tasks such as backups, and SCM check-ins and checkouts.

Also, a menu script can only interact with the Xcode user in a limited way. Often, it is in the form of dialogs generated using the StandardsAdditions scripting library. For a menu script to access and display any one of these dialogs, it has to use the osascript tool.

But a menu script cannot use the osascript tool as its command-line tool. If its declarative header is #!/usr/bin/osascript, the script will only generate errors when executed by Xcode. This prevents the script from being written in pure AppleScript.

The Xcode Menu Script Components

Xcode provides a number of built-in arguments that can appear in the arguments list. To prevent the command-line tool from interpreting them, these arguments are enclosed within a %%%{...}%%% delimiter. The most important argument is PBXName. Use this to assign a menu name to the script. That name is displayed on the Script menu each time it is rebuilt.

Also equally useful is the PBXKeyEquivalent argument. Use this argument to assign a keyboard shortcut to the script. The shortcut itself consists of a modifier key followed by a single alphanumeric character. Assume, for example, the following entries in the script's arguments list.

# %%%{PBXName=Test Script}%%%
# %%%{PBXKeyEquivalent=@B}%%%

This means the script will have a name of Test Script on the Script menu. It can also be invoked by pressing the <CMD> key together with the <B> key. To execute the script, either its name is selected from the Script menu, or its keyboard shortcut is typed on the keyboard.

Other supported modifier keys include <Opt> (represented by a tilde, '~'), <Ctrl> (represented by a caret, '^'), and <Shift> (represented by a dollar sign, '$'). Make sure to assign unique shortcut keys to each menu script. Otherwise, the wrong script or operation may be invoked if that shortcut is used elsewhere.

Handling input data

To supply data to the menu script, Xcode provides the built-in argument, PBXInput. This argument is the functional equivalent of the stdin file descriptor.

The source of data for the PBXInput argument comes from the active source file. This will be the file being edited in the Xcode's text editor pane. For instance, if the test.c file is being edited, data for the PBXInput argument will come from that file.

The PBXInput argument takes one of three possible values. The Selection value tells Xcode to use the currently selected text as the input data for the menu script. Conversely, the AllText value tells it to use the entire source text as the input data. Finally, the None value tells Xcode to provide no data to the script. The same also happens if the PBXInput argument is omitted from the menu script.

Another way of providing input data to the menu script is through the built-in argument, PBXArgument. This is used to pass parameters to the menu script. It performs the same function as a command-line option.

A PBXArgument can only have a single parameter. But a menu script can have more than one PBXArguments. To access the first nine PBXArguments, use the positional variables $1 to $9, with $1 corresponding to the very first one. If there are more than nine PBXArguments, make sure to enclose the positional number within a pair of braces. For instance, to retrieve the value of the 25th PBXArgument, use the variable ${25}.

Assume, for example, the following entries in the script's arguments list.

# %%%{PBXArgument=-r}%%%
# %%%{PBXArgument=-z}%%%
# %%%{PBXArgument=-e}%%%

The positional variables $1, $2, and $3 will then return their respective values of -r, -z, and -e.

Handling output results

Xcode also provides the built-in argument, PBXOutput, to handle the output results of a menu script. This argument is the functional equivalent of the stdout file descriptor. If the menu script does not have the PBXOutput argument, any output results it generates will be simply discarded.

The PBXOutput argument can have one of seven possible values. Each value determines how the output results are to be handled by Xcode. For instance, the Discard value tells Xcode to ignore any results generated by the menu script. This has the same effect as not adding a PBXOutput argument to the script.

The next three values tell Xcode how to display the output results onto the active source file. The ReplaceSelection value replaces the currently selected text with the output results. On the other hand, the InsertAfterSelection value appends the results to the selected text. Finally, the ReplaceAllText value replaces the entire source text with the results. Note that the resulting change in the source text is not permanent. Choosing Undo from the Edit menu can still restore the original text.

The SeparateWindow value, on the other hand, tells Xcode to display the output results in a separate window. At the time of this writing, however, Xcode does not display the results in a separate document window. Instead, it uses a modal dialog to display those results. Hopefully, future versions of Xcode will address this issue by providing both display options. In the meantime, see the script example shown in Listing 2 for a good workaround.

The next useful PBXOutput value is the Pasteboard value. It tells Xcode to store the output results onto the clipboard buffer. Choosing Paste from the Edit menu then places the results onto any editable text window. The results remain in the clipboard buffer until the next Cut or Copy operation replaces them. They can also be replaced by another menu script if its PBXOutput is also set to Pasteboard.

The last PBXOutput value is the AppendToAllText value. This value tells Xcode to place the output results at the very end of the active source file. However, this feature is broken in version 2.3 of Xcode. Any output results from a menu script are not displayed anywhere on the source file. The README files for both Xcode 2.4 and 2.4.1 also showed no signs of whether or not this bug is fixed.

The macro variables

Xcode provides a number of built-in macro variables that can be used in a menu script. It then replaces these variables with their actual values prior to script execution. Use these macros to simplify various aspects of a menu script. Make sure to enclose each macro variable within the %%%{...}%%% delimiters. This will prevent the command-line tool from accidentally interpreting them.

The first macro variable is the PBXTextLength macro. It returns the total number of characters contained in the active source file. The character count also includes control characters such as newlines (0x0d) and tabs (0x09). In short, this macro variable represents the size of the source file in bytes.

Three macro variables are used for processing a text selection. The PBXSelectionStart macro returns the number of characters before the start of the selection. Conversely, the PBXSelectionEnd return the number of characters from the start of the file up to the end of the selection. Finally, the PBXSelectionLength returns the number of characters contained by the selection. Its returned value is equal to the difference between PBXSelectionEnd and PBXSelectionStart.

Figure 3 shows how these three macros are interrelated with each other. This example assumes that the active source file contains only the five-word phrase shown. Note that, in this example, the selected text is highlighted in grey.


Figure 3. Macro variables on a text selection.

On a related note, the built-in macro PBXSelection sets the start and end of a selection. It is used to select a portion of the output result. For example, assume that a menu script generates the following output.

echo "Lorem ipsum "
echo "%%%{PBXSelection}%%%dolor "
echo "%%%{PBXSelection} sit amet"

If the PBXOutput argument is set to use the active source file, the word dolor will be selected on that file. However, make sure to use the PBXSelection macro in pairs. If Xcode does not find a matching PBXSelection macro for a previous one, it will not perform the text selection.

There are also two built-macros that return a file path. The first one, PBXFilePath, returns the absolute file path of the active source file. The path is returned as a string value, and is rendered as a Unix file path. Use this macro to manipulate the file, its contents, or its directory at the shell level.

The second macro is PBXUtilityScriptsPath. This macro returns the directory path for all the utility scripts bundled with Xcode. By default, it returns the path as

/System/Library/PrivateFrameworks/ ¬
DevToolsInterface.framework ¬
/Resources/UtilityScripts.

Use this macro to refer to any one of the utility scripts, which will be discussed next.

The utility scripts

In addition to built-in arguments and macros, Xcode also comes with a number of utility scripts. These scripts are primarily used to add modal dialogs to a menu script. Xcode users can then interact with the menu script through these dialogs.

The utility scripts use the osascript command-line tool to generate their modal dialogs. This tool sends AppleScript calls to the StandardAdditions library, which then displays the desired dialog. When a user interacts with the dialog, the tool returns the results to stdout as a string. If the user cancels the dialog, the tool sends an empty string to stdout and a cancellation message (error -128) to stderr.

At the time of this writing, Xcode comes bundled with five utility scripts. The first script, AskUserForApplicationDialog, displays a list of all applications present on the MacOS X volume. It requires two string parameters: the dialog title and the prompt message. For example,

REPLY=`%%%{PBXUtilityScriptsPath}%%%/AskUserForApplicationDialog ¬
"Application List" "Pick an application"`

displays a dialog with the title Application List and the message Pick an application. When a user selects an application, the script returns the absolute file path to that application as a string. In the above example, the returned string is stored in the shell variable REPLY.

The second utility script is the AskUserForStringDialog script. This script prompts the user for an input string. It takes a single string parameter, which is the default input value. For example, the following statement

REPLY=`%%%{PBXUtilityScriptsPath}%%%/AskUserForStringDialog ¬
"untitled"`

should display an input dialog with the string untitled as the default value. After the user types in a string and presses the Enter button, the script returns the string value to the menu script. However, this utility script has one notable flaw. Its prompt message is set to the default string value of Enter your name, and it cannot be changed. For a good workaround, see the script example shown in Listing 4.

The rest of the utility scripts are used for I/O interaction. The AskUserForExistingFileDialog script prompts the user to select a file from the MacOS X volume. It takes a single string parameter, which is the prompt message. For example, the statement

REPLY=`%%%{PBXUtilityScriptsPath}%%%/AskUserForExistingFileDialog ¬
"Choose a file to be edited"`

displays the dialog with the prompt Choose a file to be edited. When the user selects a file, the script returns the absolute file path to that file as a string.

The dialog displayed by this script uses ~/Documents as its default directory. It shows any files and directories that are hidden or invisible. Also, it resolves links to other directories. But it will not do the same for links to other files, treating them instead as actual files.

The next I/O utility script is the AskUserForFolderDialog script. This script prompts the user to select a directory from the MacOS X volume. It also takes a single string parameter for its prompt message. For example, the statement

REPLY=`%%%{PBXUtilityScriptsPath}%%%/AskUserForFolderDialog ¬
"Select a destination"`

displays the dialog with the prompt Select a destination. When the user selects a directory, the script returns the absolute file path to that directory as a string.

The dialog displayed by the script allows users to create a new directory, and to select it as well. It also resolves links to other directories. But, it will not display any directories that are hidden or invisible.

The third I/O utility script is the AskUserForNewFileDialog script. This script prompts the user to select the directory where a new file can be stored. It also prompts for a name to be assigned to that file. The script takes two string parameters: one for the prompt message, the other for the default filename. For example, the statement

REPLY=`%%%{PBXUtilityScriptsPath}%%%/AskUserForNewFileDialog ¬
"Save the backup as" "backup.file"`

displays the dialog with the prompt Save the backup as, and a default filename of backup.file. If a file exists with the same name, the dialog will display a warning alert. Also, once the user has selected a directory and a filename, the script returns the absolute file path to that new file. It will not, however, create the file.

Creating an Xcode Menu Script

The Xcode project template

Often, writing an Xcode menu script means using a third-party text editor. But why not use Xcode itself to write and install a menu script? The Xcode project template, Xcode Menu Script Action, is created primarily for this purpose. This template, as well as other support files, are available as part of the XcodeMenu installer package.

The template itself contains a starter script named myscript.sh. This script has the basic arguments list shown in Figure 2. Modify this list to the appropriate settings for this script.

The script also has a custom list containing two arguments. These arguments determine how the script is to be installed. The first one, USRDir, specifies the subdirectory that will contain the menu script. This subdirectory is then created inside the Xcode script directory.

The second argument is USRName. This specifies a unique filename for the menu script. It also specifies the two-digit number that determines the script's position on the Script menu. Always make sure to assign a two-digit number to the menu script. Also, make sure to add a dash between the number and the script's filename. Failure to do either one renders the script inaccessible from the Script menu.

For example, assume that a menu script has the following entries in its custom header.

# - Custom User Script Info -
# %%%{USRDir=75-CVS Control}%%%
# %%%{USRName=05-cvsbackup.sh}%%%

Xcode first checks to see if the subdirectory 75-CVS Control exists in the script directory. If it does not, Xcode creates a new subdirectory with that name. Next, Xcode copies myscript.sh into that subdirectory. It then renames the copy as 05-cvsbackup.sh.

The Xcode project can also have multiple scripts. Each script can have its USRName set to its source filename, as long as the required two-digit number and dash precedes that name. Each script can share the same USRDir subdirectory as the other scripts. Alternatively, it can have its own USRDir subdirectory.

Using the project template

To create a new Xcode menu script project, choose New Project from the File menu. Then, from the Project Assistant dialog, select Xcode Menu Script Action (Figure 4) and press the Next button. Assign a new name to the project, and select the directory to store it. Click on the Finalize button to create and save the new project.


Figure 4

To install and test the default source script, choose Build from the Build menu. If the build process generates no errors, choose Reset Menu from the Script menu. This will cause the menu to update its list of menu items. After a second or two has elapsed, click on the Script menu. There should be submenu entry named Test Scripts, and that submenu should have a single menu item named My Test Script (Figure 5).


Figure 5. A single menu script.

To add another source script to the Xcode project, choose New File from the File menu. Then, from the New File Assistant, choose Menu Script File and click on the Next Button (Figure 6). Assign a new name to the file, and the project and target to which it should belong. Click on the Finalize button to save the file, and have it added to the project.


Figure 6. Selecting the file template.

Choose Build from the Build menu to add the new menu scripts to the Script menu. Then choose Reset Menu from the Script menu to update its list. The submenu should now have two menu scripts as shown in Figure 7.


Figure 7. Two menu scripts.

Xcode Menu Script Examples

Counting the number of lines

Listing 1 shows one of the simplest menu scripts possible for the Xcode environment. This script uses the wc tool to count the number of lines in the source file. It then displays the resulting count using a modal dialog.

Listing 1. Count the number of source lines (lineCount.sh).

# - PB User Script Info -
# %%%{PBXName=Count the number of source lines}%%%
# %%%{PBXInput=None}%%%
# %%%{PBXOutput=SeparateWindow}%%%
# %%%{PBXKeyEquivalent=}%%%
# %%%{PBXArgument=}%%%
# %%%{PBXIncrementalDisplay=YES}%%%
#
# - Custom User Script Info -
# %%%{USRDir=90-Sample Menu Scripts}%%%
# %%%{USRName=01-linecount.sh}%%%
#
# count the number of lines in the source file
CNT_src="%%%{pbxfilepath}%%%"
CNT_LINES=`wc -l $CNT_SRC`
# parse out the count value
CNT_LINES=`echo $CNT_LINES | awk '{ print $1 }'`
# display the count results
CNT_MESSAGE="Number of lines: $CNT_LINES"
echo "$CNT_MESSAGE"

Search for a selected word or phrase

The script shown in Listing 2 is a little more sophisticated. It first stores the selected text into the SRCH_DAT variable using the cat tool. Notice the dash right after the tool. This tells cat to receive its input data from stdin.

The script first retrieves the file path to the active source file. It then determines the file path to the search.output file, and stores it into the SRCH_OUT variable. Next, the script passes the active source file to the nl tool to renumber the source lines. Afterward, it uses grep to parse out those lines that contain the SRCH_DAT pattern, and stores the results into the search.output file.

This script also demonstrates how to use Xcode to display the search results. It first converts the file path stored in SRCH_OUT to a form usable by AppleScript. It then sends a number of AppleScript calls to the osascript tool. The tool then uses these calls to coerce Xcode into opening the search.output file.

Listing 2. Searching for a selected text (selectSearch.sh).

# - PB User Script Info -
# %%%{PBXName=Search selected text}%%%
# %%%{PBXInput=Selection}%%%
# %%%{PBXOutput=Discard}%%%
# %%%{PBXKeyEquivalent=}%%%
# %%%{PBXArgument=}%%%
# %%%{PBXIncrementalDisplay=YES}%%%
#
# - Custom User Script Info -
# %%%{USRDir=90-Sample Menu Scripts}%%%
# %%%{USRName=02-selectSearch.sh}%%%
#
# retrieve the search parametre
SRCH_DAT=`cat -`
# renumber the search document
SRCH_INP="%%%{PBXFilePath}%%%"
#prepare the output file
SRCH_DIR=`pwd`
SRCH_OUT="$SRCH_DIR/search.output"
if [ -f $SRCH_OUT ];
then
   rm -f $SRCH_OUT
fi
#perform the search and save the output to the file
nl -b a $SRCH_INP | grep "$SRCH_DAT" 1> $SRCH_OUT
#display the results of the search
SRCH_OUT="OS X"`echo $SRCH_OUT`
SRCH_OUT=`echo ${SRCH_OUT//\//:}`
SRCH_OUT="\"$SRCH_OUT\""
osascript <<-APPLESCRIPT
   tell application "Finder"
       set fileref to get file $SRCH_OUT as string
       
       tell application "XCode"
         activate
         open file fileref
       end tell
    end tell
   APPLESCRIPT

Backing up an Xcode project

Listing 3 shows how a menu script can create a backup of the current Xcode project. It also demonstrates how the script uses a utility script to interact with the Xcode user.

First, the script navigates from the current working directory until it reaches the level where it finds the first .xcodeproj bundle. This is done in case the active source file happens to be stored inside a subdirectory within the project directory. Next, the script uses the AskUserForNewFileDialog utility script to prompt the user for a backup name and destination. It then stores the result into the PRJ_BCK variable.

Now the script uses the expr tool to check the contents of the PRJ_BCK variable. If the user cancels the dialog prompt, the variable will contain a null string, and the rest of the script is not executed. Otherwise, that variable will likely have a valid file path. The script then uses the tar tool to archive and compress the Xcode, and stores the backup archive onto the specified destination.

Listing 3. Backing up the active project (projBackup.sh).

# - PB User Script Info -
# %%%{PBXName=Backup the Xcode project}%%%
# %%%{PBXInput=None}%%%
# %%%{PBXOutput=SeparateWindow}%%%
# %%%{PBXKeyEquivalent=}%%%
# %%%{PBXArgument=}%%%
# %%%{PBXIncrementalDisplay=YES}%%%
#
# - Custom user script info
# %%%{USRDir=90-Sample Menu Scripts}%%%
# %%%{USRName=03-projBackup.sh}%%%
#
# initialise the following shell variable
PRJ_MSG="Save the backup as"
# navigate to the project directory
PRJ_CHK=`ls -d *.xcodeproj | wc -l`
while [ $PRJ_CHK -lt 1 ];
do
   cd ..
   PRJ_CHK=`ls -d *.xcodeproj | wc -l`   
done
# retrieve the current directory
PRJ_DIR=`pwd`
# generate a date/time tag
PRJ_TAG=`date "+%H%M%S"`
PRJ_NOM="Backup_$PRJ_TAG"
# select a backup filename
PRJ_BCK=`%%%{PBXUtilityScriptsPath}%%%/AskUserForNewFileDialog \
               "$PRJ_MSG" "$PRJ_NOM"`
# was it successful?
PRJ_CHK=`expr "$PRJ_BCK" : '.*'`
if [ $PRJ_CHK -gt 0 ];
then
   PRJ_BCK="$PRJ_BCK.tar.gz"
   # start the backup
   tar -czf $PRJ_BCK *.*
   # the backup is done
   echo "Backup created at: $PRJ_BCK"
fi

Exporting a CVS project archive

The script shown in Listing 4 demonstrates how to use CVS to export the latest copy of the Xcode project from the project archive. It also shows how to use the osascript tool to provide a workaround for the AskUserForStringDialog utility script.

First, the script checks to see if the project is currently being managed by CVS. It does this by looking for a CVS subdirectory within the project itself. If the subdirectory does not exist, the script displays the appropriate dialog message.

If the project is being managed by CVS, the script retrieves the path to the project archive from the Root file. It then uses the osascript tool to invoke the display dialog function with AppleScript. This dialog prompts the user for an export tag, offering a timestamp as the default tag. The results of the dialog are then stored into the CVS_TAG variable.

Next, the script uses the cvs tag command to apply the tag to the Xcode project. It then retrieves the project's archive name from the Repository file. Afterward, the script prompts the user for an export name and destination using the AskUserForNewFileDialog utility script. It stores the result of that interaction into the CVS_XPT variable.

Finally, the script uses the cvs export command to export a copy of the Xcode project from the archive and onto the desired destination. If it is successful, the script displays a dialog showing the directory path of the exported project.

Listing 4. Exporting from CVS (cvsExport.sh).

# - PB User Script Info -
# %%%{PBXName=Export CVS Xcode project}%%%
# %%%{PBXInput=None}%%%
# %%%{PBXOutput=SeparateWindow}%%%
# %%%{PBXKeyEquivalent=}%%%
# %%%{PBXArgument=}%%%
# %%%{PBXIncrementalDisplay=YES}%%%
#
# - Custom User Script Info -
# %%%{USRDir=90-Sample Menu Scripts}%%%
# %%%{USRName=04-cvsExport.sh}%%%
#
# check for the following subdirectory
CVS_DIR=`pwd`
CVS_DIR="$CVS_DIR/CVS"
if [ -d $CVS_DIR ];
then
   # retrieve the CVS repository path
   CVS_ROOT=`cat $CVS_DIR/Root`
   
   # prompt the user for an export tag
   CVS_TAG=`date "+%H%M%S"`
   CVS_TAG=`osascript <<-APPLESCRIPT
      tell application "Xcode"
         activate
         display dialog "Enter a CVS export tag:" ¬
            default answer ${CVS_TAG}
         return (text returned of result) as string
      end tell
      APPLESCRIPT
   `
   # was it successful?
   CVS_CHK=`expr "$CVS_TAG" : '.*'`
   if [ $CVS_CHK -gt 0 ];
   then
      # apply the tag to the sources
      CVS_TAG="v$CVS_TAG"
      cvs -Q tag $CVS_TAG
      
      # prompt the user for an export directory
      CVS_MSG="Export the project to:"
      CVS_NOM=`cat $CVS_DIR/Repository`
      CVS_XPT="$CVS_NOM$CVS_TAG"
      CVS_XPT=`%%%{PBXUtilityScriptsPath}%%%/AskUserForNewFileDialog "$CVS_MSG" "$CVS_XPT"`
      
      # was it successful?
      CVS_CHK=`expr "$CVS_XPT" : '.*'`
      if [ $CVS_CHK -gt 0 ];
      then
         # export the CVS project
         cvs -d $CVS_ROOT -Q export -R -r $CVS_TAG \
               -d $CVS_XPT $CVS_NOM
         
         echo "Project has been exported to: $CVS_XPT"
      fi
   fi
else
   echo "This project is currently not under SCM by CVS."
fi

Concluding Remarks

Menu scripts are a flexible and effective way to customize and enhance the Xcode environment. Their support for standard shell scripting languages makes them easy to learn and implement. They can add features that are essential to the workflow, but are not available in Xcode. They can automate certain tasks that are otherwise repetitive and prone to mistakes. They can also invoke external tasks without the need to exit the Xcode environment.

Without a doubt, menu scripts are one of the reasons why Xcode continues to be the preferred development tool for MacOS X.

Bibliography and References

Apple Computers. "Using Scripts to Customize Xcode". Xcode 2.3 User Guide. Copyright 2004, 2006. Apple Computers, Inc.

Cooper, Mendel. Advanced Bash-Scripting Guide. Revision 4.1. 2006 Oct 08. Online: www.tldp.org/LDP/abs/abs-guide.pdf.


JC is a freelance engineering consultant and writer currently residing in North Vancouver, British Columbia. He writes for various publications and teaches origami at his local district's public library. He can be reached at anarakisware@cashette.com.

 
AAPL
$99.02
Apple Inc.
+1.35
MSFT
$43.97
Microsoft Corpora
-0.53
GOOG
$590.60
Google Inc.
+1.58

MacTech Search:
Community Search:

Software Updates via MacUpdate

OS X Yosemite Wallpaper 1.0 - Desktop im...
OS X Yosemite Wallpaper is the gorgeous new background image for Apple's upcoming OS X 10.10 Yosemite. This wallpaper is available for all screen resolutions with a source file that measures 5,418... Read more
Acorn 4.4 - Bitmap image editor. (Demo)
Acorn is a new image editor built with one goal in mind - simplicity. Fast, easy, and fluid, Acorn provides the options you'll need without any overhead. Acorn feels right, and won't drain your bank... Read more
Bartender 1.2.20 - Organize your menu ba...
Bartender lets you organize your menu bar apps. Features: Lets you tidy your menu bar apps how you want. See your menu bar apps when you want. Hide the apps you need to run, but do not need to... Read more
TotalFinder 1.6.2 - Adds tabs, hotkeys,...
TotalFinder is a universally acclaimed navigational companion for your Mac. Enhance your Mac's Finder with features so smart and convenient, you won't believe you ever lived without them. Tab-based... Read more
Vienna 3.0.0 RC 2 :be5265e: - RSS and At...
Vienna is a freeware and Open-Source RSS/Atom newsreader with article storage and management via a SQLite database, written in Objective-C and Cocoa, for the OS X operating system. It provides... Read more
VLC Media Player 2.1.5 - Popular multime...
VLC Media Player is a highly portable multimedia player for various audio and video formats (MPEG-1, MPEG-2, MPEG-4, DivX, MP3, OGG, ...) as well as DVDs, VCDs, and various streaming protocols. It... Read more
Default Folder X 4.6.7 - Enhances Open a...
Default Folder X attaches a toolbar to the right side of the Open and Save dialogs in any OS X-native application. The toolbar gives you fast access to various folders and commands. You just click... Read more
TinkerTool 5.3 - Expanded preference set...
TinkerTool is an application that gives you access to additional preference settings Apple has built into Mac OS X. This allows to activate hidden features in the operating system and in some of the... Read more
Audio Hijack Pro 2.11.0 - Record and enh...
Audio Hijack Pro drastically changes the way you use audio on your computer, giving you the freedom to listen to audio when you want and how you want. Record and enhance any audio with Audio Hijack... Read more
Intermission 1.1.1 - Pause and rewind li...
Intermission allows you to pause and rewind live audio from any application on your Mac. Intermission will buffer up to 3 hours of audio, allowing users to skip through any assortment of audio... Read more

Latest Forum Discussions

See All

Traps n’ Gemstones Review
Traps n’ Gemstones Review By Campbell Bird on July 28th, 2014 Our Rating: :: CASTLEVANIA JONESUniversal App - Designed for iPhone and iPad Fight mummies, dig tunnels, and ride a runaway minecart to discover ancient secrets in this... | Read more »
The Phantom PI Mission Apparition Review
The Phantom PI Mission Apparition Review By Jordan Minor on July 28th, 2014 Our Rating: :: GHOSTS BUSTEDUniversal App - Designed for iPhone and iPad The Phantom PI is an exceedingly clever and well-crafted adventure game.   | Read more »
More Stubies Are Coming Your Way in a Ne...
More Stubies Are Coming Your Way in a New Update Posted by Jessica Fisher on July 28th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
The Great Prank War Review
The Great Prank War Review By Nadia Oxford on July 28th, 2014 Our Rating: :: PRANKING IS SERIOUS BUSINESSUniversal App - Designed for iPhone and iPad Though short, The Great Prank War offers an interesting and fun mix of action and... | Read more »
Marvel Contest of Champions Announced at...
Marvel Contest of Champions Announced at Comic-Con Posted by Jennifer Allen on July 28th, 2014 [ permalink ] Announced over the weekend at San Diego Comic-Con was the fairly exciting looking Marvel Contest of Champions. | Read more »
Teenage Mutant Ninja Turtles Review
Teenage Mutant Ninja Turtles Review By Jennifer Allen on July 28th, 2014 Our Rating: :: DULL SWIPINGUniversal App - Designed for iPhone and iPad The pizza power is weak when it comes to this Teenage Mutant Ninja Turtles game.   | Read more »
Exploration Focused Puzzle Game Beatbudd...
Exploration Focused Puzzle Game Beatbuddy Set to Make Transition from PC to iOS this September Posted by Jennifer Allen on July 28th, 2014 [ permalink ] | Read more »
PlanetHD
PlanetHD By Nadia Oxford on July 28th, 2014 Our Rating: :: SPACE MADNESSUniversal App - Designed for iPhone and iPad PlanetHD will keep players busy for a while, though its unpredictable physics are a handful to deal with.   | Read more »
This Week at 148Apps: July 21-25, 2014
Another Week of Expert App Reviews   At 148Apps, we help you sort through the great ocean of apps to find the ones we think you’ll like and the ones you’ll need. Our top picks become Editor’s Choice, our stamp of approval for apps with that little... | Read more »
Reddme for iPhone - The Reddit Client (...
Reddme for iPhone - The Reddit Client 1.0 Device: iOS iPhone Category: News Price: $.99, Version: 1.0 (iTunes) Description: Reddme for iPhone is an iOS 7-optimized Reddit client that offers a refreshing new way to experience Reddit... | Read more »

Price Scanner via MacPrices.net

iOS 8 and OS X 10.10 To Support DuckDuckGo As...
Writing for Quartz, Dan Frommer reports that Apple’s forthcoming iOS 8 and OS X 10.10 operating systems version updates will allow users to select DuckDuckGo as their default search engine. He notes... Read more
U.K. Hospital Using iPods and iPads To Record...
British news journal GazetteLive’s. Ian McNeal notes that the old “an apple a day keeps the doctor away” proverb is being turned on its head at http://southtees.nhs.uk/hospitals/james-cook/ James... Read more
13-inch 2.5GHz MacBook Pro on sale for $1099,...
Best Buy has the 13″ 2.5GHz MacBook Pro available for $1099.99 on their online store. Choose free shipping or free instant local store pickup (if available). Their price is $100 off MSRP. Price is... Read more
Roundup of Apple refurbished MacBook Pros, th...
The Apple Store has Apple Certified Refurbished 13″ and 15″ MacBook Pros available for up to $400 off the cost of new models. Apple’s one-year warranty is standard, and shipping is free. Their prices... Read more
Record Mac Shipments In Q2/14 Confound Analys...
A Seeking Alpha Trefis commentary notes that Apple’s fiscal Q3 2014 results released July 22, beat market predictions on earnings, although revenues were slightly lower than anticipated. Apple’s Mac’... Read more
Intel To Launch Core M Silicon For Use In Not...
Digitimes’ Monica Chen and Joseph Tsai, report that Intel will launch 14nm-based Core M series processors specifically for use in fanless notebook/tablet 2-in-1 models in Q4 2014, with many models to... Read more
Apple’s 2014 Back to School promotion: $100 g...
 Apple’s 2014 Back to School promotion includes a free $100 App Store Gift Card with the purchase of any new Mac (Mac mini excluded), or a $50 Gift Card with the purchase of an iPad or iPhone,... Read more
iMacs on sale for $150 off MSRP, $250 off for...
Best Buy has iMacs on sale for up to $160 off MSRP for a limited time. Choose free home shipping or free instant local store pickup (if available). Prices are valid for online orders only, in-store... Read more
Mac minis on sale for $100 off MSRP, starting...
Best Buy has Mac minis on sale for $100 off MSRP. Choose free shipping or free instant local store pickup. Prices are for online orders only, in-store prices may vary: 2.5GHz Mac mini: $499.99 2.3GHz... Read more
Global Tablet Market Grows 11% in Q2/14 Notwi...
Worldwide tablet sales grew 11.0 percent year over year in the second quarter of 2014, with shipments reaching 49.3 million units according to preliminary data from the International Data Corporation... Read more

Jobs Board

Sr Software Lead Engineer, *Apple* Online S...
Sr Software Lead Engineer, Apple Online Store Publishing Systems Keywords: Company: Apple Job Code: E3PCAK8MgYYkw Location (City or ZIP): Santa Clara Status: Full Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Sr. Product Leader, *Apple* Store Apps - Ap...
**Job Summary** Imagine what you could do here. At Apple , great ideas have a way of becoming great products, services, and customer experiences very quickly. Bring Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.