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


Click here to return to the 'Desktop Folder Action - Convert Safari .webloc to PC .url files' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Desktop Folder Action - Convert Safari .webloc to PC .url files
Authored by: anastas on Dec 24, '04 03:58:45PM
I spliced together this script from those found on this hint with a tutorial found on apple.com (see references in script) that will automatically convert .webloc files to .url files when dragged to the desktop.

Copy the code below into a new script (using Script Editor), for reference we will call it convert_webloc.scpt

I placed the following .scpt file (convert_webloc.scpt) into COMPUTER NAME > Library > Scripts > Folder Action Scripts, but you could obviously place it anywhere.

Then attached the script as a folder action... right-click (or cntrl + click) on the Desktop folder in your Home directory and select "Attach a Folder Action...". Select the script file (convert_webloc.scpt) and you are done!

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

-- source: http://www.apple.com/applescript/folderactions/05.html
on adding folder items to this_folder after receiving these_items
	tell application "Finder"
		set this_name to the name of this_folder
	end tell
	
	repeat with i from 1 to number of items in these_items
		set this_item to item i of these_items
		set the item_info to info for this_item
		
		-- cont. from http://www.macosxhints.com/article.php?story=20040728185233128 (osteslag)
		if (this_item as string) ends with ".webloc" then
			-- get full paths
			set weblocPath to quoted form of POSIX path of this_item
			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 adding folder items to


[ Reply to This | # ]
Desktop Folder Action - Convert Safari .webloc to PC .url files
Authored by: olegyk on Apr 17, '06 02:55:03AM
It is also possible to obtain the URL of a Loc file (having class internet location file) with the "location" property.

That will avoid using the DeRez utility.

Also instead of do shell script for writing to the new file, it can be done with "open for access file" and write ....

[ Reply to This | # ]

Desktop Folder Action - Convert Safari .webloc to PC .url files
Authored by: glitch44 on Apr 01, '07 11:14:55AM


I get "Syntax Error - Expected """ but found unknown token" when I try to run this script. Did I do something wrong?

New to applescript...



[ Reply to This | # ]
Desktop Folder Action - Convert Safari .webloc to PC .url files
Authored by: klar on Jul 23, '07 05:00:11PM

I almost didn't respond because this website forced me to register in order to leave a reply, but I did, and then had to navigate back to this page 3 times.


Anyway, the problem is insufficient quoting on the grep line, just use the version from the original post the backslashes should all be in pairs (awwww)


set cmd to devToolsPath & "DeRez -e -only 'url ' " & weblocPath &
" | grep '\\/\\* .* \\*\\/' | sed 's/^.*\\/\\* //;s/ \\*\\/$//' | tr -d '\\n'"



[ Reply to This | # ]