• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Return PDF default reader
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Return PDF default reader


  • Subject: Re: Return PDF default reader
  • From: Matt Deatherage <email@hidden>
  • Date: Sat, 31 Mar 2007 18:43:35 -0500

On 3/31/07 at 11:15 AM, kai <email@hidden> wrote:

> I guess you could try to parse the contents of a lsregister dump

Ooh, I'd hate to do that.  Then again, I hate to do it *this* way (*two*
"do shell script" statements?  Am I still me?), but this does work:

---
set tempFldr to (path to temporary items)
set myPath to (POSIX path of tempFldr) & "temp.pdf"
set myFile to POSIX file myPath

tell application "Finder" to open tempFldr  --just to watch

tell application "System Events"
    do shell script "touch " & quoted form of myPath
    set pdfApp to default application of (info for (myFile))
    do shell script "rm " & quoted form of myPath
    return pdfApp
end tell
---

I'm still a bit out of it, so there are probably better ways to create a
file and remove it than using shell scripts (maybe "open for access"),
but the goal is to create a default PDF file and then ask System Events
who would open it if you double-clicked it.

That is, let System Events talk to Launch Services instead of making my
script do it.  Note that this does require write access to your own
temporary items folder, and it is *possible* that you won't have that if
you're booting from a CD or DVD or something, but I think even netboot
gives you a writable temp folder.  (You might also want to add a random
number as part of the filename in a production script, just in case.)

This obviously would not do if it had to be repeated dozens or hundreds
of times, but it strikes me as a once-per-script task.  Feel free to mock,
improve, dissect, enhance, etc.

--Matt

--
Matt Deatherage                              <email@hidden>
GCSF, Incorporated                      <http://www.macjournals.com>

We sincerely apologize for yesterday.  It was eaten by squirrels.


 _______________________________________________
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/archives/applescript-users

This email sent to email@hidden

References: 
 >Re: Return PDF default reader (From: kai <email@hidden>)

  • Prev by Date: Re: shell script - duplex printing prefs
  • Next by Date: Re: Entourage
  • Previous by thread: Re: Return PDF default reader
  • Next by thread: (no subject)
  • Index(es):
    • Date
    • Thread