Re: Return PDF default reader
Re: Return PDF default reader
- Subject: Re: Return PDF default reader
- From: kai <email@hidden>
- Date: Mon, 15 Jan 2007 23:55:58 +0000
On 15 Jan 2007, at 09:25, Jay Louvion wrote:
I am looking for a way to return the name of the default app that
opens PDF’s (Preview, Acrobat, whatever).
Ronald Hofman kindly suggested the following:
set DefaultApp to (word -6 of (do shell script "defaults read
com.apple.Preview"))
Unfortunately, OMM it errors out with the following message: “sh:
line 2: com.apple.Preview: command not found”
Any ideas ?
If you're looking for a shell approach similar to the one you used
for the default browser, Jay, then you might try something like (one
line):
----------
set defaultApp to word -1 of (do shell script "defaults read
com.apple.LaunchServices LSHandlers | grep -A 2 'LSHandlerContentType
= \"com.adobe.pdf\";' | grep 'LSHandlerRoleAll = \"'")
----------
My own preferred approach, however, would probably be to use System
Events' Property List Suite to extract the application's bundle
identifier. While a little more verbose, this doesn't rely on text
parsing methods - which, if the file's structure changes slightly,
may render such techniques more vulnerable. In this sort of
situation, System Events is also faster (about twice as fast here).
Again, rather than merely parsing the bundle identifier, it might be
an idea to then use Finder to determine the precise value of the
required property.
Try, for example, something like:
----------
on |default application| for l
set s to l's class is in {string, Unicode text}
set l to (l as list)'s items
repeat with i in l
tell application "System Events" to set h to value of property list
item ¬
"LSHandlerRoleAll" of (property list item 1 of property list item ¬
"LSHandlers" of property list file (POSIX path of preferences
folder & ¬
"/com.apple.LaunchServices.plist") where i is in value of property
list items)
tell application "Finder" to try
set i's contents to displayed name of application file id h
(* or extract some other type of value *)
on error number -2753 (* OSAUndefinedVariable *)
set i's contents to missing value
end try
end repeat
if s then return l's beginning
l
end |default application|
set defaultApp to |default application| for "com.adobe.pdf"
--> "Preview" (* or whatever *)
----------
The subroutine should also handle lists:
----------
|default application| for {"com.adobe.pdf", "public.html", "mailto",
"webcal", ¬
"public.plain-text", "quicktime", "com.apple.applescript.script"}
--> {"Preview", "Safari", "Mail", "iCal", "TextEdit", "QuickTime
Player", "Script Editor"} (* or whatever *)
----------
---
kai
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users
This email sent to email@hidden