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


Click here to return to the 'Modified version allows for processing folders' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Modified version allows for processing folders
Authored by: ghaskins on Feb 03, '09 07:09:34AM
Instead of using bookmarks, my wife saves links in a folder hierarchy on the hard disk, which she consequently wanted to access on our Windows machine, so I created a modified version that will accept any combination of files/folders and convert all .webloc files it finds into .url files. I'm not an Applescript expert, but it was fairly simple to extend the original script to allow for this use. I also integrated fm's comment to remove the dependency on Developer Tools.

on open draggedItems
	global itemsConverted
	set itemsConverted to 0
	repeat with theItem in draggedItems
		my convertAnyWeblocs(theItem)
	end repeat
	display dialog (itemsConverted as string) & " Mac .webloc links converted to standard .url links"
end open

on convertAnyWeblocs(theItem)
	tell application "Finder"
		local fileType
		try
			set fileType to file type of theItem
		on error
			set fileType to "folder"
		end try
		
		if fileType is "folder" then
			set childItems to (every item of theItem)
			repeat with childItem in childItems
				my convertAnyWeblocs(childItem)
			end repeat
		else
			my convertFile(theItem)
		end if
	end tell
end convertAnyWeblocs

on convertFile(theFile)
	local weblocPath, urlPath, theURL, cmd
	global itemsConverted
	
	if (theFile as string) ends with ".webloc" then
		
		set weblocPath to quoted form of the POSIX path of (theFile as alias)
		set urlPath to text 1 thru -9 of weblocPath & ".url'"
		
		-- 1) get URL from .webloc file
		tell application "Finder" to set theURL to theFile's location
		if theURL begins with "http" then
			-- 2) write URL to new .url file
			set cmd to "echo '[InternetShortcut]" & (ASCII character 10) & 
				"URL=" & theURL & "' > " & urlPath
			do shell script cmd
			-- 3) delete original .webloc file, be sure to backup first
			set cmd to "rm  " & weblocPath
			do shell script cmd
			set itemsConverted to (itemsConverted + 1)
		end if
	end if
end convertFile


[ Reply to This | # ]