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
$109.57
Apple Inc.
+2.83
MSFT
$45.81
Microsoft Corpora
+0.65
GOOG
$506.28
Google Inc.
+10.89

MacTech Search:
Community Search:

Software Updates via MacUpdate

Tidy Up 4.0.2 - Find duplicate files and...
Tidy Up is a complete duplicate finder and disk-tidiness utility. With Tidy Up you can search for duplicate files and packages by the owner application, content, type, creator, extension, time... Read more
Typinator 6.3 - Speedy and reliable text...
Typinator turbo-charges your typing productivity. Type a little. Typinator does the rest. We've all faced projects that require repetitive typing tasks. With Typinator, you can store commonly used... Read more
GraphicConverter 9.5 - Graphics editor w...
GraphicConverter is an all-purpose image-editing program that can import 200 different graphic-based formats, edit the image, and export it to any of 80 available file formats. The high-end editing... Read more
Toast Titanium 12.0.1 - The ultimate med...
Toast Titanium goes way beyond the very basic burning in the Mac OS and iLife software, and sets the standard for burning CDs, DVDs, and now Blu-ray discs on the Mac. Create superior sounding audio... Read more
QuickBooks 2015 16.0.2.1422 R3 - Financi...
Save 20% on QuickBooks Pro for Mac today through this special discount link QuickBooks Pro 2013 helps you manage your business easily and efficiently. Organize your finances all in one place, track... Read more
Remotix 3.0.6 - Access all your computer...
Remotix is a fast and powerful application to easily access multiple Macs (and PCs) from your own Mac. Features: Complete Apple Screen Sharing support - including Mac OS X login, clipboard... Read more
BetterZip Quick Look Generator 1.5 - Let...
BetterZip Quick Look Generator lets you view the contents of compressed archives through OS X's Quick Look functions. Simply select an archive in the Finder, in Mail, or Spotlight and press the... Read more
Sandvox 2.9.3 - Easily build eye-catchin...
Sandvox is for Mac users who want to create a professional looking website quickly and easily. With Sandvox, you don't need to be a Web genius to build a stylish, feature-rich, standards-compliant... Read more
Pixelmator 3.3.1 - Powerful layer-based...
Pixelmator is a beautifully designed, easy-to-use, fast, and powerful image editor for OS X. It has everything you need to create, edit, and enhance your images. Pixelmator is a layer-based image... Read more
OmniGraffle Pro 6.1.1 - Create diagrams,...
OmniGraffle Pro helps you draw beautiful diagrams, family trees, flow charts, org charts, layouts, and (mathematically speaking) any other directed or non-directed graphs. We've had people use... Read more

Latest Forum Discussions

See All

Hipstify Review
Hipstify Review By Jennifer Allen on December 17th, 2014 Our Rating: :: COOL FILTERSUniversal App - Designed for iPhone and iPad Add filters, quotes, and fancy frames to your images, thanks to Hipstify.   | Read more »
Mighty Smighties Gets Evolve Cards and N...
Mighty Smighties Gets Evolve Cards and New Worlds Posted by Jessica Fisher on December 17th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Duckie Deck Card Wars Review
Duckie Deck Card Wars Review By Amy Solomon on December 17th, 2014 Our Rating: :: STYLISH GAME OF CARDSUniversal App - Designed for iPhone and iPad Duckie Deck Card Wars adapts the classic card game War for use on devices, complete... | Read more »
PDF Office Review
PDF Office Review By Jennifer Allen on December 17th, 2014 Our Rating: :: CONVENIENT PDF EDITINGiPad Only App - Designed for the iPad Want to create your own PDF files? Import them from elsewhere? Adapt a web page into a PDF? PDF... | Read more »
The Out There: Ω Edition Update will be...
The Out There: Ω Edition Update will be Releasing in 2015, Bringing Better Graphics and Additional Content Posted by Jessica Fisher on December 17th, 2014 [ permalink ] | Read more »
Pinball Planet Pro (Games)
Pinball Planet Pro 1.02 Device: iOS Universal Category: Games Price: $2.99, Version: 1.02 (iTunes) Description: - Our missionWe've always loved to play pinball games but we noticed most modern pinball games are simulators for the... | Read more »
Ultrakam 4k. The Professional Camera App...
Ultrakam 4k. The Professional Camera App. 3.0 Device: iOS Universal Category: Photography Price: $9.99, Version: 3.0 (iTunes) Description: In March 2014, Ultrakam brought Film Resolution for iPhone for the first time ever and now is... | Read more »
Email+ (Business)
Email+ 1.0 Device: iOS Universal Category: Business Price: $2.99, Version: 1.0 (iTunes) Description: Send email, fast! | Read more »
Mayor it up in SimCity BuildIt, Out Now
Mayor it up in SimCity BuildIt, Out Now Posted by Jessica Fisher on December 16th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Crusaders Quest Review
Crusaders Quest Review By Jennifer Allen on December 16th, 2014 Our Rating: :: GOTTA HIRE EM ALLUniversal App - Designed for iPhone and iPad Hire as many heroes as possible in this fun at first but grind-heavy freemium RPG.   | Read more »

Price Scanner via MacPrices.net

Holiday sales continue: MacBook Pros for up t...
 B&H Photo has new MacBook Pros on sale for up to $300 off MSRP as part of their Holiday pricing. Shipping is free, and B&H charges NY sales tax only: - 15″ 2.2GHz Retina MacBook Pro: $1699... Read more
Google Search App For iOS Gets A Major Makeov...
Google has given iOS users an early Christmas present with a substantial update of it’s not-very-often-upgraded Google Search app. Google Search has been my go-to tool for Web searches since it was... Read more
ShopKeep Apple Pay And Chip Card Reader Avail...
ShopKeep, a cloud-based technology provider to more than 10,000 small business owners to manage retail shops and restaurants with iPads, has released its new Apple Pay and chip card reader. This... Read more
Holiday sale! 27-inch 5K iMac for $2299, save...
 B&H Photo has the 27″ 3.5GHz 5K iMac in stock today and on sale for $2299 including free shipping plus NY sales tax only. Their price is $200 off MSRP, and it’s the lowest price available for... Read more
Holiday Sale! 3.7GHz Quad Core Mac Pro availa...
 B&H Photo has the 3.7GHz Quad Core Mac Pro on sale for $2599 including free shipping plus NY sales tax only. Their price is $400 off MSRP, and it’s the lowest price for this model from any... Read more
iPhone 6 Number 3 Canadian Google Search Of 2...
CTVNews.ca reports that Apple’s iPhone 6 was the third highest-trending Google Canada search topic of 2014, exceeded only by Robin Williams largely after his death by suicide in August, and the FIFA... Read more
New iPad mini 3 Counter-Top & Wall Mount...
newMacgadgets has announced new secure all-acrylic displays for the iPad mini 3 (also works fine with the mini 2, last year’s iPad mini With Retina Display, and the original iPad mini). The new iPad... Read more
Holiday sales continue, MacBook Airs for up t...
B&H Photo has 2014 MacBook Airs on sale for up to $120 off MSRP, for a limited time, for the Thanksgiving/Christmas Holiday shopping season. Shipping is free, and B&H charges NY sales tax... Read more
B&H lowers price on 27-inch 3.2GHz iMac t...
B&H Photo has lowered their price on the 27″ 3.2GHz iMac, now on sale for $1629 including free shipping plus NY sales tax only. Their price is $170 off MSRP, and it’s the lowest price for this... Read more
15-inch 2.0GHz Retina MacBook Pro available f...
B&H Photo has lowered their price on leftover 2013 15″ 2.0GHz Retina MacBook Pros to $1499 including free shipping plus NY sales tax only. Their price is $500 off original MSRP. Read more

Jobs Board

*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
Project Manager / Business Analyst, WW *Appl...
…a senior project manager / business analyst to work within our Worldwide Apple Fulfillment Operations and the Business Process Re-engineering team. This role will work Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.