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

Download NPR audio files with Safari Web Browsers

NPR has switched from publishing RealAudio streams as .ram files to .smil files. Unfortunately, the Safari web browser appears to truncate that suffix to just .smi, which tells Mac OS that the file is a Self Mounting Image file. The system attempts to mount the bogus image on the Desktop and fails, never opening the file in the RealOne Player as intended. The first file downloaded will have the name "dmg.smi". Subsequent files are named "dmg-1.smi", "dmg-2.smi", and so on.

This script watches for files with names like that to appear in your Safari Download folder. When one does appear, the script alerts you and lets you choose whether to open it in RealOne Player or ignore it and do nothing. You can disable the confirmation dialog box by changing the value of the "request_confirmation" property to "false".

If you're a better AppleScripter than I am, and you almost certainly are, please add comments to this hint and/or send any improvements to me at pheelb at yahoo dot com. I hope this improves your NPR listening!

[robg adds: I have not tested this script, but there's no potentially dangerous code involved.]

HOW TO INSTALL:

The script is implemented as a Folder Action. As an unfortunate consequence, installing it is a bit harder than dragging it somewhere and forgetting about it. Also, it requires OS X 10.2 or later (for the built-in Script Menu). Don't worry, though, the steps are simple.
  1. Launch /Applications -> AppleScript -> Script Editor, and paste the script below into a new script window. Make sure you paste into the main area of the window and not the part labeled "Description". Select File -> Save, and give it a name meaningful to you. Under "Format" choose "Compiled Script" if it isn't the default. Save it to the Desktop.

  2. Activate the Script Menu (standard with OS X 10.2 and later). This is easy: "Just drag the ScriptMenu.menu icon, located in the AppleScript folder in the Applications folder, to the menu bar at the top right of your screen and let go." (quoted from Apple's ScriptMenu page)

  3. Once the Script Menu is in your menu bar, select "Open Scripts Folder" from the menu (it's the last item). The location of this folder is /Users -> yourname -> Library -> Scripts. Inside it should be a folder called "Folder Action Scripts." Create it if it isn't there, and put the script file you saved in step one inside it.

  4. Now select Script Menu -> Folder Actions -> Attach Script to Folder. In the dialog box that appears, select the name of this script and press "OK". You'll now be asked what folder you want to attach the script to. Select your Safari Download folder, which is the Desktop unless you've changed it in the Safari preferences.

  5. Finally, select Script Menu -> Folder Actions -> Enable Folder Actions.
Damn, that was long. Sorry. But now it's ready to go. Go to npr.org in Safari and listen to something. The script will detect when the new file appears in your Downloads folder and ask you what to do. Press "Open with RealOne Player" to listen, or press "Cancel" to ignore it. If you don't want to be asked, change the property called "request_confirmation" from true to false and resave the script.
-- controls whether or not to display a confirmation dialog box. change value 
-- to 'false' if you want the script to automatically open files with names 
-- like "dmg*.smi" in RealOne Player.
property request_confirmation : true

-- set the amount of time before dialogs auto-answer.
property dialog_timeout : 30

on adding folder items to this_folder after receiving added_items
  
  -- find out how many new items have been placed in the folder
  set the item_count to the number of items in the added_items
  
  -- continue only if just one item was placed in the folder
  if the item_count is 1 then
    try
      tell application "Finder"
        --get the name of the folder
        set the folder_name to the name of this_folder
      end tell
      
      set the_item to item 1 of the added_items
      
      tell application "Finder"
        set item_name to the name of the_item
      end tell
      
      set saved_delimiters to AppleScript's text item delimiters
      set AppleScript's text item delimiters to {"."}
      
      set the_base_name to the first text item of item_name
      set the_suffix to the last text item of item_name
      
      set AppleScript's text item delimiters to saved_delimiters
      
      if (the the_base_name begins with "dmg") and (the the_suffix is "smi") then
        if request_confirmation is true then
          --create the dialog box alert string
          set alert_message to "Folder Actions Alert:" & return & return & ¬
          "New item in " & folder_name & ": " & item_name & return & return
          
          display dialog the alert_message buttons {"Open with RealOne Player", "Cancel"} ¬
          default button 2 with icon 1 giving up after dialog_timeout
          
          set my_choice to the button returned of the result
        else
          set my_choice to "Open with RealOne Player"
        end if
        
        if my_choice is "Open with RealOne Player" then
          tell application "RealOne Player"
            activate
            open the_item
          end tell
        end if
      end if
      
    end try
  end if
  
end adding folder items to
    •    
  • Currently 3.25 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[18,190 views]  

Download NPR audio files with Safari | 9 comments | Create New Account
Click here to return to the 'Download NPR audio files with Safari' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
don't go to all this trouble!
Authored by: joey03 on Mar 20, '03 11:51:24AM

You don't need a script. Remember that MacOS X can use creator and type codes in addition to file extensions. So all you need to do is do a get info on one of the downloaded .smi files and specify RealOne Player as the app always to be used to open it. That's all you need to do. The system should henceforth distinguish between RealOne Player .smi files and DiskCopy .smi (self-mounting image) files.



[ Reply to This | # ]
don't go to all this trouble!
Authored by: ylon on Mar 20, '03 12:40:35PM

I tried that myself a couple of days ago and it did not work. Any detailed explanation as to how you got it to work as it is not as simple as you seem to make it appear?



[ Reply to This | # ]
don't go to all this trouble!
Authored by: pheel on Mar 20, '03 06:44:41PM

This was my first instinct too, but I couldn't make it work. When you change the default application in the file's info box, you get a confirmation dialog. It says in effect that all files with that extension will now be opened with the app you chose. So it does to some degree depend on the files extension.

I tried downloading an actual self-mounting image file after doing is, and RealOne tried to open it. Is there some way to get finer-grained prefs than this, so that it does distinguish between the two kinds of files?



[ Reply to This | # ]
Download NPR audio files with Safari
Authored by: bluehz on Mar 20, '03 02:12:40PM

One thing that has really made my transition to Safari and its limited understanding of URI's and MIM types is an oldy but a goody. Application called "Vince" allows you to associate URI's and MIME types to speific applications - like the old Internet Config and IE prefs. Vince is a standalone app that youopen and modify then close, the author also has a similar pref pane called "More Internet". Not sure quite what the difference is other than the fact that you can not add specific types into Vince's list of known types, and More Internet you can. Vince's list is quite extensive though has served me well.

Not sure it will work in this situation - nevertheless its worth throwing into your toolbox.



[ Reply to This | # ]
Download NPR audio files with Safari
Authored by: gconway on Mar 20, '03 02:28:35PM

I don't know if there's something "wrong" with my Safari but it has no problem downloading .smil files correctly. I just checked NPR, picked an Archived Realplayer file, and double-clicked it as usual. It appeared in my download folder as atc3.smil, showing a Realplayer icon, and played just fine. So for me this script isn't useful. However, I have noticed a problem with Safari correctly downloading Quicken .forte files from my banking service. Unlike Camino and other browsers (and despite the correct settings in Internet config, which I checked using Misfox), Safari does not properly identify these files (type and creator) for Quicken. Go figure.

---
____________
Gerry Conway



[ Reply to This | # ]
Download NPR audio files with Safari
Authored by: osxpounder on Mar 20, '03 04:17:53PM

I think NPR may have switched back; all I can tell you is that when I go to www.npr.org right now, I find a link to a RAM file.

BTW, I tried to download the "free" RealOne Player at www.real.com, only to find that their page has circular links--i.e., I can't download the free player! The link leads to yet another promotional page for the "premium" player, and that page has a link to [c'mon everybody, join in ....] the first page with the free download link. I can't find a way out of it.

So I guess I'll be listening to NPR via QuickTime, eh?

---
--
osxpounder



[ Reply to This | # ]
Download NPR audio files with Safari
Authored by: bluehz on Mar 20, '03 04:50:32PM

My Safari downloaded the Safari file just fine also - doesn't launch RealPlayer - but I can click on the d/l file and it works.



[ Reply to This | # ]
Download NPR audio files with Safari
Authored by: pheel on Mar 20, '03 07:14:24PM

Downloading a statically served file with a .smil extension works fine (I assume you downloaded one of the links in the "NPR Audio Online" box in the left column of the site).

Many of the SMIL files from NPR are served dynamically from a PHP script, though. They started using this after adding Windows Media support; the script appears to determine your media preference and then sends the correct type of file. The SMIL files served this way end up with a .smi extension instead of .smil. This is where the problem occurs.

For an example, try listening to one of the individual audio segments from today's Morning Edition.



[ Reply to This | # ]
Download NPR audio files with Safari
Authored by: jeichorst on Mar 27, '04 09:46:31PM

Thank you for your script. I was actually experiencing a different problem in that Safari downloaded "ram", "rm" (et. al.) files would not automatically launch RealOne and play. I had previously tried all tricks known to me (i.e., using More Internet, cmd-i on the file and designating to open with and open all with RealOne, checking to see that the plug-ins were installed correctly, etc.) to no avail. Of course, I could always go to my Safari download folder and double click the file and RealOne would launch and play. But I thought, why do that when AppleScript should provide me with a quick fix. So I decided that a folder action script would be the best work around. However, being a novice with AppleScript I didn't know where to start. Your script provided me with exactly the starting point I needed. I ended up making two alternate versions. One to just auto launch the designated file types in RealOne circumventing the pop-up dialog. The other with the dialog in tact. End result, I have my fix AND you have helped me to start playing more seriously with AppleScript. The later actually being the bigger thrill for me. So, thank you!!!



[ Reply to This | # ]