[Pythonmac-SIG] Using Finder to open app by id

Ned Deily nad at acm.org
Sat Aug 22 21:25:33 CEST 2009


In article 
<3AE7CF31-E00C-447A-B6BF-0ED8A99F88D9 at securityevaluators.com>,
 Charles Miller <cmiller at securityevaluators.com> wrote:
> So I was hoping to figure out how to do that AppleScript line locally,  
> and then try to do it remotely as well.  The real AppleScript I wish  
> to run in py-appscript is:
> 
> set remoteMachine to "eppc://user:pass@192.168.1.3"
> set remoteFinder to application "Finder" of machine remoteMachine
> using terms from application "Finder"
> 	tell remoteFinder
> 		open application file id "com.apple.Preview"
> 	end tell
> end using terms from
> 
> But I figured I'd start easier and just try to launch a local app with  
> Finder.  Any ideas on how to do the original question (or even better  
> the above) using py-appscript?  Thanks a million.

After some experimenting, I was able to use a remote Finder to either 
just launch Preview or open a document and launch Preview.  Here's what 
worked:

>>> from appscript import *
>>> remote_finder = app(url='eppc://user:pass@hostname/Finder')
>>> # launch Preview
>>> remote_finder.startup_disk.folders["Applications"].application_files[
         'Preview'].open()
>>> # alternatively, open document with default application,
>>> #                      launching if necessary
>>> remote_finder.startup_disk.folders['Developer'].files[
         'About Xcode Tools.pdf'].open()

I was able to launch by bundle id locally:
>>> local_finder = app('Finder')
>>> local_finder.startup_disk.folders["Applications"].application_files[
         its.id == "com.apple.Preview"].open()

but remote references failed with:
   OSERROR: -1731
   MESSAGE: Unknown object type.

I'm sure HAS can explain what needs to be done to make such something 
like that work remotely; perhaps you have to construct lower-level 
references manually.  On the other hand, perhaps you don't really need 
to use the bundle id if the application name is good enough.

-- 
 Ned Deily,
 nad at acm.org



More information about the Pythonmac-SIG mailing list