| Personal Collections: Some Pictures and Some Little Mac Utilities |
|---|
| AppleScripts for the Finder and FrameMaker |
| [ Main
| Pictures
| Macintosh Utilities
| AppleScript for Eudora
| Contact me
/ Kontakformular
| About me ]
|
[Back to main Macintosh page.]
Here's a list of small AppleScripts I've written for the Finder and for FrameMaker, an application for technical documentation. They were mostly created for just one particular purpose, so they are probably not useful for the majority of Macintosh users. However, if you've actually hit one of these problems, you might want to try one of these scripts. They are free, but as always, I'm not responsible for any damages they inflict on your system (i.e. standard disclaimers apply).
All the scripts are available here in pure text form; open the appropriate page in your browser, select all the text and copy it into a new window in Script Editor, the free editor for AppleScript that is installed on any new Macintosh.
Use these scripts at your own risk! I'm not responsible for any damage or loss of data caused by these scripts. Since they all come with source code, feel free to change and improve them, but please don't distribute them without acknowledgement for the original code. If you do distribute your version, I would be grateful if you could send me a copy.
These were written to replace the shortcut commands that StuffIt Deluxe offers in Magic Menu, one of its control panels; they will expand or stuff any items in the Finder. I've been using StuffIt Deluxe version 4 for quite some time, but when I switched to Mac OS 8.5, I decided not to purchase the upgrade to version 5. When used with OSA Menu (see below), these two scripts allow expanding and stuffing of Finder items with keyboard shortcuts. Obviously, they are far from perfect, but it's a start...
For running the two scripts, you will need the StuffIt Commands Scripting Addition. It was written by Leonard Rosenthol, who also created the extension OSA Menu, which installs a system-wide menu from which AppleScripts can be run. Both the Stuffit Scripting Addition (a beta version) and the OSA Menu extension can be found on his ftp site, ftp://ftp.lazerware.com. Also necessary is a version of the StuffIt Engine extension, version 4 or later; these are part of any version of StuffIt Deluxe, StuffIt Expander, DropStuff etc.
Note that there is a User Break command in the StuffIt Scripting Addition v5.0b2, i.e. you will be dropped into the debugger when expanding an archive! This should be corrected in a future version of StuffIt Commands; there is nothing I can do about this, it's not caused by my scripts. If you feel comfortable enough with ResEdit, you can patch StuffIt Commands by eliminating the User Break code; I've done that with my copy and haven't seen any problems with the patched version so far...
Installation: open a new document in the Script Editor, copy the script from the web page, paste the contents into the new Script Editor window, save it as a compiled script. For using the script under OSA Menu, you might want to add a shortcut command at the end of its name; suggestions are found below. The compiled script should be copied to the Script folder that OSA Menu installs in the System Folder (standard under Mac OS 8.5 anyway), more precisely into the "Finder Scripts" folder. (With just some minor changes, you can transform these scripts into Drag & Drop applications, of course.)
Compresses the selected items into a new archive (which is named <archive>.sit, where <archive> is the name of the selected item if only one was selected, otherwise the name is simply "Archive.sit"). When used under OSA Menu, name the compiled script e.g. "Stuff \S", so you can stuff any file or folder by selecting it in the Finder and pressing command-S. Note that aliases are not resolved when stuffing! This behaviour can be changed easily (see Script source code).
Expands the selected items into the same folder. Under OSA Menu, name this script e.g. "Expand \U" to allow the keyboard shortcut Command-U to trigger it.
[Acknowledgement: most of the code for handling book files is directly taken from the AppleScript samples distributed with FrameMaker. ]
Unfortunately, FrameMaker has been abandoned on the Macintosh; Adobe, the current owner, decided that they won't produce a version for Mac OS X. As an owner of version 5.5, I had been waiting for an OS X version and decided not to upgrade to versions 6 and 7, which still ran only under the older Mac OS 9 system version. Now it seems that there's no future for FrameMaker on Macs, I've been looking at other tools for writing long documents (starting with TeX).
FrameMaker installs a menu entry where you can install your own scripts. The following scripts have been written in a way that they can be copied directly into the Scripts folder that is found in the Modules folder (which in turn is in the same folder as the FrameMaker application). They all assume that FrameMaker is already running (which is true if you run these scripts from FrameMaker's menu...).
Since its AppleScript support is quite extensive, many functions that are missing in FrameMaker itself can be implemented with AppleScripts. Here are a few examples:
If you ever had to change the language for all paragraph styles, this script will make it more convenient. It will change all paragraph styles with a specific language (or any language except "None", or all languages) to a new language you set in a dialogue. If a book window is in front, all documents in that book will be changed. This version runs with FrameMaker 5.1 and only handles paragraph languages (in FrameMaker 5.5, language is also a property of character styles). Furthermore, the hyphens in the two languages Canadian-French and Swiss-German confuse AppleScript because they are actually not allowed in property names. Therefore, the low-level codes have been used; when compiling, they will be replaced by the proper language names. However, the next time you open this script and recompile it, you will get an error because these names are now interpreted as Canadian minus French... FrameMaker 5.5 corrects this problem and uses slightly different names. You will have to look them up in the on-line manual and insert the names in the script source.
For identifying the FrameMaker application this script uses the double-tell method. However, in its current form, it only works under System 7.x. For Mac OS 8.x, you will have to change this to a more general form (email me if you need help).
NOTE: FrameMaker (both version 5.1.x and 5.5.x) will remove any overrides in the paragraph formats when changes to them are made via AppleScript! There is currently no workaround for this, but an enhancement request was logged with Adobe, the producer of FrameMaker.
This script should be saved as a stand-alone application; after saving, assign 300 KB RAM to it (in the Finder Info window). For installation in FrameMaker's Script menu, see above, or consult your manual for FrameMaker (and the on-line help). This script needs the Dialog Director Scripting Addition, a free osax for using windows and dialogue boxes with AppleScript. Dialog Director v0.7, by Christopher E. Hyde, can be found at http://www.hylight.demon.co.uk/DialogDirector/.
[Also available as a compiled script (BINHEX, StuffIt 4 archive), and in a FrameScript version for FrameScript 1.2 and later.]
FrameMaker 5.5.6 still doesn't support search and replace on the book level. After some hints on the framers mailing list, I had a look through the SDK for FrameMaker 5.5.6 and wrote an AppleScript that helps with replacing text through all files of a book. This is far from perfect: because it basically simulates user input, alerts and dialogs have to be dismissed by the user; FrameMaker always asks for confirmation when it receives the command to replace all occurrences of a text in document. And if the search text wasn't found in a document, a dialog will tell you so; you will have to click on the OK button to dismiss this alert box.
Furthermore, the AppleScript can't check which button was pressed in the Set Search dialog at the beginning. If you want to cancel the command, choose the Cancel button in the dialog that appears after the Set Search dialog is dismissed; this will stop the script without replacing any text.
Some further problems are:
The commands for displaying the Set Search dialog and the global replace are issued using fcodes (with Frame commands, which is part of FrameMaker's AppleScript dictionary). According to the SDK documentation, most of the fcodes have equivalent F_APIxxx() functions, but for search and replace, this does not seem to be the case, i.e. they are not officially documented (although present in the header files). Therefore, writing a "proper" API client would be much more work. That's why I decided to release this AppleScript despite its limitations.
How to use this script:
Open a new browser window with the link above, select the whole text in that window and copy it to the clipboard. Open the Script Editor (Apple's free editor for AppleScripts, part of the standard system installation), create a new document and paste the text into the window. Compile the script; it will ask you to locate your copy of FrameMaker. Finally, save the window as a compiled script into the Scripts folder within the Modules folder of FrameMaker (see above). If this folder doesn't exist yet, create it in the Finder.
Start this script with a book window as the frontmost window. To be on the safe side (and to avoid the active document problem described above), close all other windows (documents and books). The script will open the first document in the book and display a dialog to set the search and replace values; your text will only be accepted if you click on the Set button. However, even if you click on the Cancel button, the script will still continue; to stop the script, click on the Cancel button in the following alert box. To continue, either click on the OK button (which will leave all documents of the book open and unsaved after the script quits) or the OK with Save button (which will save and close each document after it has been processed).
At the beginning of handling each file, a dialog appears asking you if you want to continue although Undo won't work. Click on the OK button to continue; if you click on the Cancel button, no text will be replaced in the current document, and the next file will be opened.
This is a simple script that zooms the frontmost document (or all documents in a book) to fit the current page (or rather, screen size). This is useful if e.g. you want to set the window size of all documents of an on-line help system to the same size before you lock all files (and locking the document could also be implemented via AppleScript, of course).
I've tested this script under FrameMaker 5.5.6 only; it might work in earlier or later versions, too.
Comments, corrections and suggestions are welcome.