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

Create cross-platform URL shortcut files Internet
Creating a double-clickable web link is as simple as dragging the address from Safari to the desktop. Very convenient, unless you want to share the file with people stuck on Windows. The zero-byte .webloc file won't make them any wiser -- the address was stored in the resource fork, which means it will vanish if you try to send it to their PC.

Microsoft has their own way of creating web shortcuts, .url files. In fact, all of Windows' Internet Explorer bookmarks are stored that way; all of them in a separate tiny file. Anyway, the format is pretty simple, nothing you can't write in TextEdit in a few seconds:

[InternetShortcut]
URL=http://www.macosxhints.com
Save it as something.url and you are done. The good thing about this is that Mac OS X/Safari also supports these .url links, or does it? This had me stumped for a good while: some of my .url files would work fine and load in Safari, while some would just open an empty Safari window without loading anything, even though the same file worked properly in Windows.

Here's the catch: don't forget to add a closing line feed at the end. Apparently Safari is picky about that and the lack of it will result in the aforementioned empty window.

    •    
  • Currently 3.20 / 5
  You rated: 5 / 5 (10 votes cast)
 
[45,364 views]  

Create cross-platform URL shortcut files | 23 comments | Create New Account
Click here to return to the 'Create cross-platform URL shortcut files' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create cross-platform URL shortcut files
Authored by: gdsimms on Jan 22, '04 11:37:50AM

Wouldn't an applescript facilitating creating links this way in Safari be nise to post in this thread?



[ Reply to This | # ]
Create cross-platform URL shortcut files
Authored by: Fofer on Jan 22, '04 11:51:52AM

Now you're talkin', gdsimms! A drag-and-drop conversion (for .webloc -> .url) would be pretty darn handy as well.



[ Reply to This | # ]
Create cross-platform URL shortcut files
Authored by: ecco on Jan 22, '04 01:05:55PM
This script creates an URL shortcut on your desktop. Put it in your Safari scripts folder ~/Library/Scripts/Applications/Safari and launch it from the script menu.

try
	tell application "Safari"
		activate
		set theURL to URL of (document of window 1)
		set theTitle to name of window 1
	end tell
	set theTitle to first word of theTitle
	set res to "[InternetShortcut]
URL=" & theURL
	
	do shell script "echo \"" & res & "\" > ~/Desktop/" & theTitle & ".url"
on error x
	activate me
	display dialog x
end try



[ Reply to This | # ]
Create cross-platform URL shortcut files
Authored by: jrybolt on Jan 22, '04 05:39:21PM
Just a refinement of the above script to rename the end file to the whole title of the page. It seems to work fine, however I am testing it to make it a little more error proof. Here is the start.

try
	tell application "Safari"
		activate
		set theURL to URL of (document of window 1)
		set theTitle to name of window 1
	end tell
	set theTitleLong to theTitle & ".url" as string
	set theTitleShort to first word of theTitle & ".url"
	set res to "[InternetShortcut] URL=" & theURL
	do shell script "echo \"" & res & "\" > ~/Desktop/" & theTitleShort
	set theTitleShort to theTitleShort as string
	set the source_folder to path to desktop folder as string
	set this_item to (source_folder & theTitleShort) as alias
	tell application "Finder"
		set the name of this_item to theTitleLong
	end tell
on error x
	activate me
	display dialog x
end try
Hope this helps someone
btw great idea.

[ Reply to This | # ]
Script the Finder to create Mac OS X links
Authored by: scriptguy on Jan 22, '04 08:56:36PM
tell application "Finder"
	make new internet location file at desktop to 
		"http://www.apple.com" with properties {name:"Apple Link"}
end tell


[ Reply to This | # ]
Script the Finder to create Mac OS X links
Authored by: OSX_Apprentice on Jan 23, '04 06:36:17AM
Hello. Can anyone tell me what this special character...
...means in an AppleScript?

[ Reply to This | # ]
Line continuation or something like that...
Authored by: jecwobble on Jan 23, '04 09:54:56AM

I believe it allows you to take a statement that belongs on one continuous line and break it into two or more lines for readabilitie's sake.



[ Reply to This | # ]
Thanks! + New v. of Script Editor wraps automatically
Authored by: OSX_Apprentice on Jan 23, '04 04:12:59PM

Thank you! I suspected it was something like that but became suspicious.

Before posting my question, while trying to search for an answer, I did stumble across the following new feature of Script Editor version 2:
* Auto-wrapping of long script statements

(Source: http://www.apple.com/applescript/scripteditor/ )

I was almost going to say that is seems like that option-L character is a thing of the past, but I just realized that manual line breaks will still be necessary on websites like this one (to maintain readability) so the option-L thing will probably remain.

Regards.



[ Reply to This | # ]
OnMyCommand
Authored by: ssevenup on Jan 22, '04 09:44:33PM

If I can find the time, the hot ticket would be an OnMyCommand item that provides a "Save URL for PC" context menu item.

--Shweeet ;-)

Of course it's only useful on Cocoa browsers. Mozilla, Firebird and such only provide their own context menu items. For those (I use Firebird) you need a droplet to drag the url link onto. Applescript should be up to that challenge with a little help.

--MM

---
Mark Moorcroft
ELORET Corp. - NASA/Ames RC
Sys. Admin.



[ Reply to This | # ]
OnMyCommand
Authored by: dik on Jan 23, '04 08:48:05AM

er. OK beng completey stupid how do I run applesrcipts from Safari?



[ Reply to This | # ]
Create cross-platform URL shortcut files
Authored by: Fofer on Jan 22, '04 11:50:02AM

Nice tip, and thanks. Now wouldn't it would be nice if Safari created these cross-platorm compatible .url files in the first place?



[ Reply to This | # ]
Create cross-platform URL shortcut files
Authored by: xcgr on Jan 22, '04 05:02:45PM

Perhaps but I don't think it's reasonable to expect Apple to implement every single Microsoft-specific way of doing something. Especially when it isn't an actual, industry-standard format.



[ Reply to This | # ]
Create cross-platform URL shortcut files
Authored by: OSX_Apprentice on Jan 23, '04 07:04:58AM

Industry standard... Hmmmm...

Well, as far as I am concerned, any chance to avoid using a resource fork in OS X should be embraced. Whether the data contained in the file itself is useful on another platform or not, putting that data in the resource fork prevents it from even reaching the other platform.



[ Reply to This | # ]
Create cross-platform URL shortcut files
Authored by: _merlin on Jan 22, '04 06:42:58PM

Safari is emulating the behaviour of IE for Mac (yes, Microsoft decided IE for Mac should use a different URL file format, and the WAF, or Web Archive format used by IE for Mac still isn't supported by IE for Windows, either).



[ Reply to This | # ]
Create cross-platform URL shortcut files
Authored by: OSX_Apprentice on Jan 23, '04 08:15:21AM

I cannot agree. At least not if you are talking about IE 5.2.3 on Mac OS X. IE creates not .webloc files with URLs in their resource forks, but .url files with URLs in their data forks, preceded by "[InternetShortcut]
URL=" just as previous posts have indicated.

Which version of IE do you mean that Safari is emulating?

Netscape 7.1 for OS X, however, emulates Safari behavior by creating the same resource-based .webloc files.

IE for Windows creates the same type of .url files as IE for OS X, but with some additional data ("BASEURL=" for example) that seems to be neither crucial nor detrimental to the functionality of the files regardless of on which platform they are being used.

Safari and IE for OS X both understand both .url and .webloc files, but Netscape 7.1 for Mac does not seem to comprehend .url files.



[ Reply to This | # ]
Stupid question
Authored by: hamarkus on Jan 22, '04 03:31:25PM

Apparently, TextEdit creates linefeeds when you hit enter. Do all OS X (or all Cocoa) programms do this? I thought Mac used to use carriage returns.



[ Reply to This | # ]
Stupid question
Authored by: xcgr on Jan 22, '04 05:08:03PM
Apps in Mac OS 9 and earlier tended to use CR's to end lines, aka Mac-style line endings. Most OS X apps, particularly those written to the Cocoa frameworks, tend to use UNIX-style line endings. I believe BBEdit Lite will let you specify either kind as well as DOS-style endings.

[ Reply to This | # ]
Stupid question
Authored by: hamarkus on Jan 22, '04 06:24:23PM

You are right about BBedit lite, Project builder allows it as well. But it would be nice if I could somehow check a file created with a certain app, to see what line break it is using.
I've figured out, that using the 'cat filename' command in the Terminal, shows me all file contents if linefeeds are used, and only the last line if carriage returns are used.



[ Reply to This | # ]
Stupid question
Authored by: raster on Jan 23, '04 10:02:45AM

I use flip as mentioned in this hint...



[ Reply to This | # ]
Create cross-platform URL shortcut files
Authored by: raster on Jan 23, '04 09:57:31AM

If only I could get Mozilla to open the link instead of Safari...



[ Reply to This | # ]
Create cross-platform URL shortcut files
Authored by: greybird on Jan 29, '04 12:31:22AM

Here is my version, this one keeps full length titles. the main difference is that the title is surrounded by quotes, so bash does not interpret the spaces. The other change is I have two echo statements for better readability.

try
tell application "Safari"
set theURL to URL of (document of window 1)
set theTitle to name of window 1
end tell

do shell script "echo \"[InternetShortcut]\" > ~/Desktop/\"" & theTitle & ".url\""
do shell script "echo \"URL=" & theURL & "\" >> ~/Desktop/\"" & theTitle & ".url\""

on error x
activate me
display dialog x
end try



[ Reply to This | # ]
Create cross-platform URL shortcut files
Authored by: g4macuser on Feb 03, '04 03:45:05AM

what does "add a closing line feed at the end" mean. how do i do this?



[ Reply to This | # ]
Create cross-platform URL shortcut files
Authored by: aLibros on Apr 01, '05 03:39:06PM

TextEdit added too many additional formatting characters for me. However, TextWrangler, the freeware simple version of BBEdit from Bare Bones, was quick and easy.

My 2 cents.

Jay
Audis Libros



[ Reply to This | # ]