Resources on OSX

david bovill david at openpartnership.net
Wed Sep 21 14:41:29 EDT 2005


Been trying to work out how to get the resource infor out of webloc  
files using Rev and found this article about using Applescript and an  
OSX command line tool:

     http://www.macosxhints.com/article.php?story=20040728185233128

I am looking to be able to create and access the url inside these  
webloc files. This seems to be stored in the resource fork - so I  
though I'd use the built in Rev commands but these return empty for  
webloc files - not too up on resources in OSX - are the Rev commands  
only for OS9?

Here is the AppleScript:

property devToolsPath : "/Developer/Tools/" -- path to free Apple  
Developer Tools

on open draggedFiles
   local theFile, weblocPath, urlPath, theURL, cmd
   repeat with theFile in draggedFiles
     if (theFile as string) ends with ".webloc" then
       -- get full paths
       set weblocPath to quoted form of POSIX path of theFile
       set urlPath to text 1 thru -9 of weblocPath & ".url'"
       -- 1) get URL from .webloc file
       set cmd to devToolsPath & "DeRez -e -only 'url ' " &  
weblocPath & ¬
         " | grep '\\/\\* .* \\*\\/' | sed 's/^.*\\/\\* //;s/ \\*\\/ 
$//' | tr -d '\\n'"
       set theURL to do shell script cmd
       if theURL begins with "http" then
         -- 2) write URL to file
         set cmd to "echo '[InternetShortcut]" & (ASCII character 10)  
& ¬
           "URL=" & theURL & "' > " & weblocPath
         do shell script cmd
         -- 3) rename file using MvMac now that we have Developer  
Tools anyway
         set cmd to devToolsPath & "MvMac " & weblocPath & " " & urlPath
         do shell script cmd
       end if
     end if
   end repeat
end open

Anyone got an idea how to do this in Transcript?


More information about the use-livecode mailing list