Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Add basic AppleScript support to Preview Apps
I was looking for a way to batch print a directory of over 900 tiff files for work, and figured a basic AppleScript (very basic, as I don't know AppleScript) would do it. However, I couldnt' get it to work as you can't close window 1 or document 1 or whatever in Preview via AppleScript. So at best, my script would load all the documents, but not print more than one.

I looked around on the web quite a bit and finally found this tidbit that worked for me. Open the Preview.app package (control-click on it and choose Show Package Contents from the pop-up menu), then edit the info.plist file by adding a new boolean key set to Yes:
NSAppleScriptEnabled -- Boolean -- Yes
Save the changes, then quit and restart both Preview and Script Editor, you can now have AppleScript go through a directory of tiffs (or presumably any documents that open in Preview), open and print them, and close them one by one with a basic AppleScript. My previous solution was to use GraphicConverter to batch convert the documents to a giant multipage tiff, and then print it using GraphicConverter, which is just not particularly quick. This solution is much better.

[robg adds: I tested this by duplicating Preview, and then using Property List Editor to add a New Child to the Root level, with the item name, class, and value as shown above. I then used Script Editor's File: Open Dictionary command to browse the various scriptable apps -- and my copy of Preview showed up with the basic AppleScript library. I would think this technique should work to add basic AppleScript support to other applications...]
    •    
  • Currently 3.86 / 5
  You rated: 5 / 5 (7 votes cast)
 
[16,312 views]  

Add basic AppleScript support to Preview | 8 comments | Create New Account
Click here to return to the 'Add basic AppleScript support to Preview' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Add basic AppleScript support to Preview
Authored by: redsweater on Oct 02, '06 08:08:50AM
The basic approach will work with any app, but it's likely to yield better results with Cocoa-based apps, because a lot of the higest level scripting supporting (references to windows and documents) is handled by the Cocoa API.

Anybody who wants to read more about this very specific example (Preview) can check out my blog entry where I described it in detail:

http://www.red-sweater.com/blog/150/minimal-scriptability

---
--
Daniel Jalkut
http://www.red-sweater.com/

[ Reply to This | # ]

the lp utility would print tif files easily
Authored by: kd4ttc on Oct 02, '06 08:14:09AM

The utility lp is the unix line printer utility. The following would send all .tif files to print:

cd directory
lp *.tif



---
Steve Holland



[ Reply to This | # ]
the lp utility would print tif files easily
Authored by: klktrk on Oct 02, '06 11:13:08AM

Happiness is a warm gun, bang bang shoot shoot.

Thank you.



[ Reply to This | # ]
the lp utility would print tif files easily
Authored by: JadeNB on Oct 02, '06 01:33:47PM

I've never tried printing a .tiff file, but be careful sending items blindly to lpr -- .dvi files, for example, just print out pages and pages and pages and pages of garbage.



[ Reply to This | # ]
Add basic AppleScript support to Preview
Authored by: wordsofwisedumb on Oct 02, '06 09:57:49AM

I wonder why this isn't enabled by default. Could it just be an oversight or is there some reason for it?



[ Reply to This | # ]
Add basic AppleScript support to Preview
Authored by: redsweater on Oct 02, '06 10:19:50AM

It's probably because with the flag enabled, the AppleScript support is on the whole very incomplete and buggy. It's not good enough to warrant calling it "scriptable," even though it does allow some useful functionality.

Apple should make Preview actually scriptable.


---
--
Daniel Jalkut
http://www.red-sweater.com/



[ Reply to This | # ]
Add basic AppleScript support to Preview
Authored by: Eddie the Elder on Oct 08, '06 12:19:27PM

Or, you can set up an Automator workflow:

Ask for Finder Items >
Get Folder Contents >
Print Images



[ Reply to This | # ]
Next steps after adding basic AppleScript support to Preview
Authored by: rpgoldman on Sep 09, '08 07:23:19AM

I have done this modification to Preview successfully, for which many thanks.

Now I'm left with the next question --- where do I go to find out what kind of actions I can script with this basic cocoa-based scripting capability?

I can't get a dictionary out of the newly-scriptable Preview app, and I don't know about how to find what is offered by Cocoa by default (as should be obvious, I am a real Mac novice, although I have a lot of Unix experience).

I'm particularly interested in being able to ask Preview "from outside" to open a document and jump to a specified location in it.

thanks!



[ Reply to This | # ]