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.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »
Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links below... | Read more »
Marvel Future Fight celebrates nine year...
Announced alongside an advertising image I can only assume was aimed squarely at myself with the prominent Deadpool and Odin featured on it, Netmarble has revealed their celebrations for the 9th anniversary of Marvel Future Fight. The Countdown... | Read more »
HoYoFair 2024 prepares to showcase over...
To say Genshin Impact took the world by storm when it was released would be an understatement. However, I think the most surprising part of the launch was just how much further it went than gaming. There have been concerts, art shows, massive... | Read more »
Explore some of BBCs' most iconic s...
Despite your personal opinion on the BBC at a managerial level, it is undeniable that it has overseen some fantastic British shows in the past, and now thanks to a partnership with Roblox, players will be able to interact with some of these... | Read more »

Price Scanner via MacPrices.net

You can save $300-$480 on a 14-inch M3 Pro/Ma...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
24-inch M1 iMacs available at Apple starting...
Apple has clearance M1 iMacs available in their Certified Refurbished store starting at $1049 and ranging up to $300 off original MSRP. Each iMac is in like-new condition and comes with Apple’s... Read more
Walmart continues to offer $699 13-inch M1 Ma...
Walmart continues to offer new Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBook for sale by... Read more
B&H has 13-inch M2 MacBook Airs with 16GB...
B&H Photo has 13″ MacBook Airs with M2 CPUs, 16GB of memory, and 256GB of storage in stock and on sale for $1099, $100 off Apple’s MSRP for this configuration. Free 1-2 day delivery is available... Read more
14-inch M3 MacBook Pro with 16GB of RAM avail...
Apple has the 14″ M3 MacBook Pro with 16GB of RAM and 1TB of storage, Certified Refurbished, available for $300 off MSRP. Each MacBook Pro features a new outer case, shipping is free, and an Apple 1-... Read more
Apple M2 Mac minis on sale for up to $150 off...
Amazon has Apple’s M2-powered Mac minis in stock and on sale for $100-$150 off MSRP, each including free delivery: – Mac mini M2/256GB SSD: $499, save $100 – Mac mini M2/512GB SSD: $699, save $100 –... Read more
Amazon is offering a $200 discount on 14-inch...
Amazon has 14-inch M3 MacBook Pros in stock and on sale for $200 off MSRP. Shipping is free. Note that Amazon’s stock tends to come and go: – 14″ M3 MacBook Pro (8GB RAM/512GB SSD): $1399.99, $200... Read more
Sunday Sale: 13-inch M3 MacBook Air for $999,...
Several Apple retailers have the new 13″ MacBook Air with an M3 CPU in stock and on sale today for only $999 in Midnight. These are the lowest prices currently available for new 13″ M3 MacBook Airs... Read more
Multiple Apple retailers are offering 13-inch...
Several Apple retailers have 13″ MacBook Airs with M2 CPUs in stock and on sale this weekend starting at only $849 in Space Gray, Silver, Starlight, and Midnight colors. These are the lowest prices... Read more
Roundup of Verizon’s April Apple iPhone Promo...
Verizon is offering a number of iPhone deals for the month of April. Switch, and open a new of service, and you can qualify for a free iPhone 15 or heavy monthly discounts on other models: – 128GB... Read more

Jobs Board

IN6728 Optometrist- *Apple* Valley, CA- Tar...
Date: Apr 9, 2024 Brand: Target Optical Location: Apple Valley, CA, US, 92308 **Requisition ID:** 824398 At Target Optical, we help people see and look great - and Read more
Medical Assistant - Orthopedics *Apple* Hil...
Medical Assistant - Orthopedics Apple Hill York Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Now Read more
*Apple* Systems Administrator - JAMF - Activ...
…**Public Trust/Other Required:** None **Job Family:** Systems Administration **Skills:** Apple Platforms,Computer Servers,Jamf Pro **Experience:** 3 + years of Read more
Liquor Stock Clerk - S. *Apple* St. - Idaho...
Liquor Stock Clerk - S. Apple St. Boise Posting Begin Date: 2023/10/10 Posting End Date: 2024/10/14 Category: Retail Sub Category: Customer Service Work Type: Part Read more
Top Secret *Apple* System Admin - Insight G...
Job Description Day to Day: * Configure and maintain the client's Apple Device Management (ADM) solution. The current solution is JAMF supporting 250-500 end points, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.