ChemDraw and Word compound numbering on Mac
A while back I got this question
”I’m about to hit the tedious part of writing my chemistry PhD thesis in Microsoft Word: having all mentioned compounds numbered in text and in the chemdraw imported files. My question: is there any automated option for this task or do I have to insert every number manually? In particular renumbering after adding a new compound in the middle of the text”
There are a couple of ways to do this in LaTex (http://www.jkwchui.com/2010/03/writing-chemistry-with-latex-33/) and (http://piti.exroot.org/konwerter/) but in my experience LaTex is not particularly popular among chemists. However help is at hand, I’ve just been sent details of a brilliant applescript that works with ChemBioDraw and Word.
The process is described in detail here (http://www.martinp23.com/blog/2013/03/chemdraw-and-word-compound-numbering-on-mac/) so I won’t give anymore details just to add that one thing I’ve been using in recent Chemdraw scripts is
tell application id "com.cambridgesoft.ChemDraw"
It avoids the problems with application naming with different versions of Chem(Bio)Draw Std/Pro/Ultra.
There are many more applescripts here.
Chartsmith added to list of data analysis tools
I’ve just added Chartsmith to the list of data analysis tools.
Chartsmith is the premier charting and graphing application for Mac OS X. Built from the ground up on Mac OS X technologies, this application will make you and your data hum. Whether for scientific data visualization, for business presentation, or for graphics publishing, Chartsmith makes charting and graphing quick and easy.

Chartsmith supports a variety of chart types and can import from Excel or ascii text files. There is also Applescript support for automating workflows.
There is a comprehensive listing of data analysis tools for Mac OS X here.
AppleScriptObjC Explorer Updated to version 2.5
AppleScriptObjC Explorer is a script editor that takes advantage of AppleScript’s ability to call Cocoa methods in OS X 10.6 and later. AppleScriptObjC — AppleScript with the added ability to call MacOS X’s Objective-C-based frameworks using AppleScript syntax.
New in AppleScriptObjC Explorer 2.5.0
- Script stepping. You can now step through scripts a statement at a time using new Step, Resume and Resume to Selection commands.
- Updates to exported apps. Exported apps get individually named executables, plus correct name in their application menus.
- Bug fixes. Fixes to compiling, saving as .applescript files, and logging time-stamps.
There more details on the Applescript Resources Page.
Cheminformatics on a Mac
I gave a talk at the Cambridge Cheminformatics meeting last week, I’ve put the slides here. It was more of a demonstration than a talk but the slides give an overview and links to the various tools.
Updated
A couple of people have asked for a pdf version of the slides for download.
Automating Exporting to Evernote
I had an interesting email from Geoff Hutchison who is using an iPad mini for taking notes using Notability the notes can be typed, handwritten using a stylus, or images. Notability does not export directly to Evernote an app that can capture and synchronise notes between multiple platforms including iPad and desktop. The other feature that makes Evernote interesting is it provides handwriting recognition, thus making the handwritten notes text searchable.
Geoff had a Automator service that imported the Notability notes that had been saved to Dropbox into EverNote, however he wanted a better way to name the notes created in Evernote. As it turned out the best way to do this was to use Applescript, you can read the full details here.
Script Debugger updated
Script Debugger 5.0.5 is a free maintenance release addressing a series of issues that came to light following the release of Script Debugger 5.0. This maintenance release improves compatibility with Mac OS X 10.8 by introducing support for bundle IDs in applets and droplets.
There are details of more Applescript tools in the Applescript Resources
Restarting the lmgrd license server
I use Moe for molecular modeling work, this uses a license.dat file in each installed MOE root directory that must be updated with the contents that you have been given by CCG (either by hard copy or e-mail). You can use any ASCII text editor (I used BBEdit) to edit the file. The FlexLM license manager lmgrd must be configured and run. Usually this runs quietly in the background and needs little intervention, however I've found that on some occasions the server quits (perhaps after updates) and needs to be restarted. However since it is something I don't need to do regularly I always spend a while working out the exact syntax. So I created this short Applescript to restart the server. Each time MOE gets updated you need to change the folder path, and I’ve updated the details to reflect this.
Using ChemBioDraw with MOE
As I mentioned in my recent review of MOE 2012 there is now support for using Marvin as an external 2D chemical drawing package, but what happens if you want to use another drawing package? Well that is where Applescript comes to the rescue, using Applescript support for shell scripts and one line of SVL (scientific vector language) we can use ChemBioDraw as the external editor. Full details of the script are here.

The Applescript section contains more tutorials, scripts and resources.
Applescript Pages
I did a little housekeeping on the Applescript pages, many thanks to those readers who reported bad links etc. it is much appreciated.
PublishPlot has been updated
PublishPlot has been updated and is now available from the Mac App store, it is a very handy tool for creating publication quality plots from any text based table of data.
PublishPlot is scriptable using either Applescript or Python.
New in version 1.1 is a tool bar to display x,y location when hovering over a plot, new fitting options and the ability to apply mathematical transforms to any two curves. There are also new export functions and bug fixes.
PublishPlot is included on the page of data analysis tools
EventScripts
EventScripts is a simple application for triggering AppleScripts or shell scripts whenever certain events occur.
The listing of events a quite comprehensive and includes such things as Volumes mounted or unmounted, computer wakes, screenshot taken application launched etc.
Now added to the Applescript Resources Page.
AppleScriptObjC Explored 4th edition
The fourth edition of AppleScriptObjC Explored, the indispensable reference to AppleScriptObjC, is now available, this guide written by Shane Stanley is absolutely essential for anyone wanting to access the Cocoa frameworks from Applescript.
Since the release of the third edition there have been significant changes to Xcode, and subsequently how applications are developed. Unfortunately, but inevitably, things have become a bit more complicated.
The new edition covers the changes that have been introduced in Xcode 4.4 and later, as well as in OS X 10.8, plus other new material and projects.
Changes include new projects covering drag-and-drop in tables and making an application scriptable, plus an expanded Xcode section with a subsection on mastering build settings. There are also several new chapters in the Reference section. Code for more than 25 projects is included.

The price is $29.95 and there are upgrade options for previous purchasers.
A really great book I’ve added to the AppleScript resources page.
AppleScript Library
I’ve just come across this fantastic AppleScript Library a collection of invaluable scripts and routines to make up for missing standard functionality. Currently there are libraries available for string manipulation, a files and folders library, iWork, a URL library and a number library.
A really great resource I’ve added to the AppleScript resources page.
Mac OSX Automation archive
The Mugginsoft application automation archive provides access to a browsable repository of automation documentation for a wide range of OS X applications. Documentation is provided for automation via AppleScript and the ScriptingBridge.
Added to the Applescript Resources page
Macscripz
I’ve just come across another site providing applescripts, Macscripz.
MacScripz are just really simple scripts. They basically function as tweaks to your system. A script can range from simply deleting a file in your OS to altering a previous setting. What most scripts on this site will do is change a setting set by Apple initially to change a core behavior on your system. For example, the tweak Cloak&Dagger forces Finder (on OS X 10.7 and up) to display files Apple hides from its users. Every script on Scripz.com is pre-screened, so don't ever worry about harming your system with any of our tweaks, we only upload quality content.
I’ve added it to the Applescript Resources Page.
Script Debugger 5.0.3 Released
Script Debugger 5.0.3 is a free maintenance release addressing a series of issues that came to light following the release of Script Debugger 5.0. This maintenance release makes Script Debugger fully compatible with Mountain Lion (Mac OS X 10.8) and addresses a number of stability and performance issues.
Script Debugger 5 updated
Script Debugger is an indispensable tool for anyone writing applescripts. If you are not familiar with this application it is worth watching the tutorials
Download Script Debugger 5.0.2
Bugs closed in the 5.0.2 release:
- 17584 Resolved a crash that can occur when closing a paused document with leaked resources (e.g. unclosed files opened with the ‘open for access’ command).
- 17570 The Recompile command is once again operational.
- 17565 Corrected a problem where Script Debugger would not quit if the top window is an Event Log window.
- 17489 Resolved a problem where Script Debugger would crash opening multiple document tabs on 10.6.4 systems.
- 17548 Resolved a crash that happens when the event log window is opened, closed, reopened and then closed while the document remains open.
- 17528 Script Debugger reopens scripts in their tabs rather than in separate windows following a crash.
- 17521 Corrected a problem where text selections may not be drawn properly following a Replace All operation.
- 17512 Resolved a problem where Script Debugger may report a parameter error (-50) when a script stops on 10.6.4 systems.
- 17517 Improve the presentation when confirming document saving while closing a window with multiple dirty tabs.
- 17487 Libraries added from the Application Support folder now default to ‘Relative To Application Support’.
- 17480 Resolved a problem where Script Debugger crashes when launched on 10.6.4 systems.
- 17505, 17543, 15974 Resolved a series of memory related bugs that may improve overall stability.
- 17494 Improved performance when opening and compiling longer scripts.
There is a page of applescript resources here.
Chocolat Mac text editor
AppleScriptHTML updated
AppleScriptHTML coverts AppleScript source code to HTML representing styles and formatting.
http://www.script-factory.net/software/ScriptEditor/AppleScriptHTML/en/index.html
AppleScriptHTML's features. * Clean HTML * Styles are applied by Cascading Style Sheets. It is easy to customise styles after HTML generation.
- Script Link
- Can adding a link to open the AppleScript code in AppleScript Editor. This function is useful for displaying sample codes
In version 2.4, the support of inline css is added.
Script Debugger has been updated
Script Debugger an advanced script editor has been updated.
Improved Inline Find & Replace
Inspector Window and Result Drawer Unification
Script Debugger 5.0 combines Script Debugger 4.5′s various floating inspector panels and its Result drawer into three ‘tabs’ displayed along the right-hand side of each document.
New Bundle Editor
Script Debugger 5.0 offers a new bundle editor where you can manipulate the resources contained within a bundled script or a script application.
Floating Mini Debugger
This new window floats above all your applications.
New Value Explorer
A central feature of Script Debugger is its value Explorers which let you inspect values. For Script Debugger 5.0, value Explorers have been completely re-implemented and simplified. The result is a much more powerful and efficient tool for examining values and exploring the objects and properties offered by the scriptable applications that you control in your scripts.
Element Filtering
Script Debugger 5.0’s new Scope Bar lets you remove unwanted information from Explorers. For example, unselecting the ‘Empty Elements’ filter removes empty elements from the Explorer’s display.
Improved Handling of Large Element Collections
Script Debugger 4.5 could slow down when displaying large element collections, such as the rows in a database. Script Debugger 5.0 avoids this problem by initially displaying only the first 30 rows. Data is then retrieved from the application for only those rows visible in the Explorer. Other rows are read only when they are scrolled into view. Press the new show more button to view additional rows.
New Apple Event Log
Script Debugger 5.0 introduces an entirely new Apple Event Log which is integrated directly into the script window.Apple Events are now retained even when the log is not visible, allowing you to look at the event log without having to plan ahead. Additionally, you can change formats (source, raw, AEPrint) on the fly without having to re-run your script.
Explorable Local Variables
When stepping through handlers, local variables containing object references can be explored in Script Debugger 5.0. Additionally, object references passed into handlers can show the target application.
Conditional Breakpoints
Script Debugger 5.0 lets you assign conditions and actions to breakpoints.
Separate Running & Debugging Toolbars
Script Debugger 5.0 offers two toolbar configurations: one for when debugging is disabled; and another for when debugging is enabled. You can customize the toolbar based on how you are using Script Debugger 5.0.
Script Debugger 5.0 improves its object model diagrams by showing element (one-to-many) relationships, and property (one-to-one) relationships.
Improved Spotlight Indexing
Fully 64-Bit Native
Adding drop shadows to chemical structures
As part of my day job I maintain Drug Discovery Resources a website intended to act as a resource for scientists undertaking drug discovery. One part of the site has a section on bioisosteres including many examples http://www.cambridgemedchemconsulting.com/resources/bioisoteres/ in which the chemical structures are shown with dropped shadows.
I use ChemBioDraw to draw the structures and then save as PNG files with a transparent background. The structures are then dropped onto webpages created using RapidWeaver, within RapidWeaver there is an option to add dropped shadows to images. I was recently asked whether there was any other way to create the same effect and Matt at macosxtips suggested using ImageMagick. This applescript droplet allows you to do so by simply dropping the file.
Copy file to Dropbox and email link
A while back I posted a script that copied a file to a users MobilMe Public folder and created an email link to that file. With the imminent demise of MobileMe a couple of people have asked me for a script that does the same but uses Dropbox.
This script shows how to copy a file to your Dropbox Public folder and then email a link to it.
Script to email Chemical Structures
A reader commented that they often emailed ChemBioDraw .cdx structures to colleagues who it turned out did not have a copy of ChemBioDraw to view them, whilst it is possible to convert the cdx file to other formats using OpenBabel they usually just ended up exchanging an image. They asked if there was a better solution and this is an ideal task for Applescript. This script assumes the structure you want to email is open in ChemBioDraw, it will create an email using Apple Mail containing the structure as a SMILES string, and embed the .cdx file together with an image in PNG format.
KosmicTask
KosmicTask is an integrated scripting environment for Mac OS X. Whilst Mac OS X supports a number of scripting technologies either via it’s UNIX roots (Shell scripting , Perl etc.) or via Cocoa Framework Scripting using Apple’s scripting bridge (Applescript, Ruby, Python etc.) you can end up using a different script editor for each scripting language. KosmicTask allows you to script in a wide variety of languages from within a single editor. KosmicTask uses a plugin architecture that allows it to support a range of scripting languages, details of the languages supported by KosmicTask are shown below:-
- AppleScript
- AppleScript Cocoa - AppleScriptObjC
- Bash Shell
- C Shell
- C and C++
- F-Script Cocoa
- Java
- JavaScript
- JavaScript Cocoa - JSCocoa
- Korn Shell
- Lua
- Lua Cocoa
- PHP
- Perl
- Python
- Python Cocoa - PyObjC
- Ruby
- Ruby Cocoa
- Tcl
- Tenex C Shell
- Z Shell
KosmicTask also supports another very capable means of achieving automation - appscript. Appscript is supported by both Ruby and Python an alternative to the ScriptingBridge.
It also allows sharing of scripts with other KosmicTask users via the local shared network.

I’ve also added it to the list of Applescript Resources.
Applescript to report installed and enabled extensions
When Apple released Safari version 5 one of the most important new features was the support for extensions. Extensions are a great way to add features to Safari to personalise web browsing, they enable the addition of features that you find useful. There is a listing of Extensions that might be useful for chemists and judging by the weblogs these are of significant interest. If you are working with them however it is a bit of a pain to check which are installed and which are enabled. This applescript is a very neat way of getting a report, it also serves as a demonstration of how to link to shell scripts, in particular using the unix command cat, a standard Unix utility that concatenates and lists files, to generate the report.
ASObjC Runner released.
ASObjC Runner is an invaluable scriptable faceless background helper application. It has a dictionary with a range of commands focused on the areas where vanilla AppleScript comes up short. It adds the ability to use the power of Cocoa frameworks within Applescript.
You use it like a scripting addition, except you address the commands to the application. It provides better string handling (e.g. change case, encoding URL’s, regular expression, formatting dates), list sorting and filtering, improved file handling and progress dialog boxes.
I’ve added to the page of Applescript Resources
Scripting the Chemical Identifier Resolver Updated
I was reminded that whilst scripting menu items was the traditional way of controlling ChemDraw the more recent releases allow control by scripting commands. This is a major advance since menus can change or be translated into other languages. I’ve thus updated the script.
I was asked if it would be possible to do the same thing for other drawing packages such as MarvinSketch?
The answer is yes but because MarvinSketch does not have applescript support we have to do it slightly differently. Rather than using scripting commands we script system events to evoke the “Paste” command.
Full details of the script are here
Scripting the Chemical Identifier Resolver
The name to structure feature in ChemBioDraw is very useful but is pretty much limited to systematic names and certainly does not support other chemical identifiers like CAS Numbers. There are a number of online services that do support these sort of functions but you end up having to cut and paste from different web sites. This is where the Chemical Identifier Resolver script comes into play.
AppleScriptObjC Explored
The 'AppleScriptObjC Explored' Addenda and Errata page has been updated to cover a change made in Xcode since version 4.0 came out. <http://www.macosxautomation.com/applescript/apps/errata.html>
AppleScriptObjC Explorer v2.2 is now available. It's a free update to existing users, and incorporates all the changes in the last beta version, plus built-in updating.
Myriad Helpers 1.0.2 is now available. It's a minor update, offering a new method fordTrig: to give access to trigonometry functions. <http:www.macosxautomation.com/applescript/apps/helpers.html>
AppleScriptObjC Explored Third edition
Over the years I’ve migrated from Applescript Studio applications to AppleScriptObjC using Xcode 3 and last week I made the transition to Mac OSX 10.7.x and Xcode 4. With each transition there has been a very steep learning curve and to be honest the documentation provided by Apple has been woefully inadequate. Thankfully Shane Stanley has stepped up to the plate and provided a definitive guide for this people who want to build applications using applescript. AppleScriptObjC Explored is the definitive guide to building AppleScript Objective-C applications. It guides you step-by-step through the process of integrating the power of Cocoa into your AppleScript applets and applications, demonstrating each concept and technique in fully editable and annotated example projects.
The latest edition also includes a detailed navigation of Xcode 4, for those of us who had just learnt our way around Xcode 3 the changes made in the new version are significant and the section explaining where everything is and what they are for is invaluable, in fact it is probably worth reading this section before you start trying to write your first application.
Once you have a basic understanding of Xcode adding an interface to your script becomes largely point and click.
There is also a very useful section on trouble-shooting, and explanation of “gotchas” that will crop up occasionally.
The book comes with a collection of over 20 ready built Xcode tutorials/projects that demonstrate key implementations but that can also act as starting points for your own projects.
Whilst I keep a list of applescript resources, I suspect that AppleScriptObjC Explored is probably the most useful.
Scripting the Organic Chemistry Reference Resolver
The Organic Chemistry Reference Resolver is an invaluable web service that takes as input a text reference to a published article in a variety of formats and then finds and displays the corresponding publication.
The real beauty of a web service is that it can be accessed via a variety of means, including an applescript. This applescript uses as input either text that has been copied to the clipboard or the text the user has typed into a text box, it submits the request to the web service and displays the result in the web browser.
An alternative to the Delete Restore folder applescript
Matt over at MacOSX Tips has sent me an alternative script, in this rather than deleting the restore file it is simply enabled or disabled. This script demonstrates the implementation for Safari.
Delete Restore folders for selected applications
One of the new features in Lion is the ability of applications to resume activity at the point an application was quit. This means that when you reopen an application it will open and display all the documents you were editing in the state when you quit the application. This is obviously very useful but there are times when you may not want confidential documents automatically opened and displayed when you open an application.
This Applescript allows you to delete the restore folder for specified applications.
There are more applescripts here.
Update to AppleScriptObjC Explorer
Version 1.1.0 is now available. It includes several localizations, more frameworks, and the ability to check for and install updates. See http://www.macosxautomation.com/applescript/apps/runner.html for details.
