tom djb,
Without putting the script on the dock, how would I run it, eg, from within Safari?
If the AppleScript is saved to your Home/Library/Scripts folder, it can be accessed through the Scripts Menu. The Scripts Menu would need to be enabled first using the AppleScript Utility, found within the AppleScript folder. Check "Show Script Menu in menu bar." You would subsequently notice a squiggly AppleScript icon appear on your menu bar. Clicking on it would allow you to select the script while working in Safari, or any other application for that matter.
Another option would be to use a keyboard shortcut program such as
Spark. Using Spark you can assign a key combo or a function key to open the saved AppleScript, so that after highlighting your selection you might need only press a single key to bring up the print dialog with your selection ready to print.
...but right now it is printing the applescript itself.
This shouldn't happen as long as the following conditions are met:
1) The script was saved as an application.
2) The script application is being run from the Dock, Scripts Menu or by using a keyboard shortcut.
3) You're not switching to the Finder or any other application in between the time you highlight your selection and the time you launch the script. A clue to the technical reason for this can be found in the second line of the script, "keystroke tab using command down." This command simulates what goes on under ordinary circumstances when you hold down your Command key and press Tab -- the Application Switcher palette appears, and does so with the +previous application used+ highlighted. The long and short of it is that the script needs to look at Safari as the previous application rather than the current one because the current application when running the AppleScript is going to be the script itself. Therefore, if for example, you were to highlight your selection and then switch to the Desktop to double-click on the saved AppleScript, the script would look at the Finder as the last application used, thus breaking the script and likely resulting in your printing the script icon instead of the selection you highlighted in Safari.
Admittedly, the script can be intolerant unless certain conditions are met, and this intolerance does indeed serve to point out some of the limitations of
GUI Scripting on the whole.
Several good suggestions in this thread; Good luck with whichever you choose...
Regards, Andrew99