Saving a website shortcut to the desktop

Forums » Opera for Windows/Mac/Linux » Desktop wish-list

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

Go to last post

18. June 2007, 00:46:09

eugenm

Posts: 102

Saving a website shortcut to the desktop

I am not sure why something as trivial as this has not been implemented in O before?..
When I browse (and I do a lot) I do come across websites that I want to review right afterwards, or anyway soon. For that I do save to the webstite URL shortcuts to the desktop. Saving shortcuts to the desktop is trivial in IE, while in O you have to un-maximize O in order to be able to drag the link to the desktop.

Can you implement the IE functionality - Save Shortcut to Desktop?
Thanks.

18. June 2007, 02:21:37

AyushJ

Posts: 4754

button

Drag the button to a toolbar and click it to create a shortcut on desktop.

18. June 2007, 13:34:14

eugenm

Posts: 102

That should be sufficient, I guess, even though it does require loading another button, which in turn may lead to increased RAM usage. But at least in my case that should be ok.
Yet, it does not seem to work?
No shortcut is created on the Desktop when I click the button.

18. June 2007, 21:34:38 (edited)

AyushJ

Posts: 4754

The button doesn't work for some websites (e.g. if there is an & in URL ) sad

If you want a working button then Save a VBS file with following code in C:\Windows\ folder and name it create_shortcut.vbs :
Set wsArgs=WScript.Arguments
if wsArgs.length=0 Then WScript.Echo "Error":WScript.Quit
Set ws=CreateObject("WScript.Shell")
pos=Instr(wsArgs(0),"//")+2
name=Mid(wsArgs(0),pos,InStr(pos,wsargs(0),"/")-pos)
name=InputBox("Enter name of shortcut :","Name of new shortcut",name)
If Not Len(name) Then WScript.Quit
set sc=ws.CreateShortcut(ws.SpecialFolders("Desktop")+"\\"+name+".url")
sc.targetpath=wsArgs(0)
sc.save()


Then use this button to create a shortcut on desktop:
button

18. June 2007, 18:58:01

eugenm

Posts: 102

Done what you said.
It doesn't work.
When I click the button all I get is for the vbs file to open in Notepad?..

18. June 2007, 20:58:57

eugenm

Posts: 102

I get.. "there is no script engine for file extension .vbs"

18. June 2007, 21:33:07

AyushJ

Posts: 4754

Ok. Click Start > Run and paste the following line and click OK:
cmd /c assoc .vbs=VBSFile

19. June 2007, 00:27:53

eugenm

Posts: 102

Bingo!

I must say that now you are getting the geek in me interested in some coding...
I guess I will join the club soon. I learn a couple of things here.

Now if only:
- The whole code was contained in an easy to install solution - a simple drag and drop - without the need to use the VBS code... This way everyone could use the button.
- Don't you think that such option would be useful to users, if implemented in O? I suggest that this functionality is built into 9.5, if possible.
- Would you mind get the Save As prepopulated with teh Page Title entry? That would be great.

Great job and thanks.

19. June 2007, 01:13:35

eugenm

Posts: 102

I just realized that another enhancement would be awesome, again to be done within O.
When saving webpages it would be great to be able to highlight text and then save the annotated page (say using single page .mht).

Thanks.

19. June 2007, 02:00:38

Operetta

Posts: 626

Originally posted by eugenm:

I just realized that another enhancement would be awesome, again to be done within O.
When saving webpages it would be great to be able to highlight text and then save the annotated page (say using single page .mht).

Thanks.



wizard

19. June 2007, 18:42:12

eugenm

Posts: 102

AyushJ,

Any ideas? I went through the WScript and the O ini options.
I see no possibility to pass on or to capture the page's title?
Also, when pressing the Cancel button a shortcut is still created to the desktop, albeit one without a title.

I am starting to believe that the title piece cannot be achieved without JS, but then I am not an expert coder so I may be missing some option to adjust your code and still achieve the desired result.

Thanks. This is cool..

19. June 2007, 22:02:06

AyushJ

Posts: 4754

Originally posted by eugenm:

Also, when pressing the Cancel button a shortcut is still created to the desktop, albeit one without a title.



I fixed the VBS code in the post above. copy/paste again smile


I dont think that the title part is possible sad

20. June 2007, 03:24:20

eugenm

Posts: 102

Thanks AyushJ
The change works just fine, thanks.

But the absence of the title prepopulation makes the button inconvenient.
It's actually faster to adjust the browser window size, drag and drop the link, and remaximize...
Sigh...

Good try. I learned a thing or 2 about the buttons and the WScript.

One thing that I learned about the O9 buttons is that it should have a capability to pass the page title to the vbs code. If it can pass on the URL it should certainly be able to capture and pass title as well.

What's the deal? Thanks.

20. June 2007, 07:22:28

AyushJ

Posts: 4754

bigsmile

Save the following code as a VBScript file (or overwrite the create_shortcut.vbs):
Set WSArgs=WScript.Arguments:Dim Name
if WSArgs.length<>1 Then WScript.Echo "Arguments Error!":WScript.Quit
Set fs=CreateObject("Scripting.FileSystemObject")
Set ws=CreateObject("WScript.Shell")
Set Rxp=New RegExp:Rxp.Global=1:Rxp.Pattern="[\\/:\*\?""<>\|]"
Set file=fs.OpenTextFile(WSArgs(0),1,vbFalse)
Name= file.ReadLine
URL=file.ReadLine
file.Close

Desktop=ws.SpecialFolders("Desktop")
Do Until Check(Rxp.Replace(Name,"-"))
Name=InputBox("A file with this name already exists, please type a different name:","Enter name:",Name)
If len(name)=0 then wscript.quit
Loop

Function Check(lName)
If fs.FileExists(Desktop & "\" & Name & ".url") Then Check=False Else Check=True
Name=lName
End Function
Set SC=ws.CreateShortcut(Desktop & "\" & Name & ".url")
SC.TargetPath=URL
SC.Save


In Opera, click Tools - Preferences - Advanced- Downloads - Click ADD
Type create/shortcut in MIME Type field and select Open with other application and select the VBS script as the application
Click OK > OK



Now use this button :
button

Now the script will automatically create the shortcut (without asking you the name) if there is no shortcut on desktop with same name smile

20. June 2007, 12:49:55

eugenm

Posts: 102

Now that's the spirit ...
The new button just opens up the vbs file in Notepad.
Need some adjustment..

Thanks.

20. June 2007, 13:29:46

AyushJ

Posts: 4754

Tools - Preferences - Advanced - Downloads
Double click create/shortcut in list and change the Open with other application line to:
wscript.exe "C:\Windows\create_shortcut.vbs"

20. June 2007, 20:18:45

eugenm

Posts: 102

Not working.
Here are my settings:


Thanks.

21. June 2007, 18:11:59

AyushJ

Posts: 4754

What happens when you click the button ??

Try these and try:
1. Remove the vbs from the File extension field in the dialog box.
2. Run these commands from Command Prompt (note that this will change the default action of VBS files):
  1. assoc .vbs=VBSFile
  2. ftype VBSFile=%SystemRoot%\System32\WScript.exe "%1" %*

21. June 2007, 20:17:26

eugenm

Posts: 102

#2.1 worked. Thanks a lot.
Now I do have an option that is sufficient for my normal use.
I hope that the Opera team can add some solution within the browser code..
This should not be so complicated.
Thanks again. Case closed and over to the Dev team...

And if the Opera dev team reads this thread - please have a look at the Save page with annotations idea and see if that could be implemented. Thanks Opera!

29. June 2008, 23:57:06

DrGuz

Posts: 4

UPDATED for 9.50


Ayush's trick has been working well for many months, but changes in Opera version 9.50 seem to have broken it. I offer here a revised edition that should work both with 9.50 and previous versions, along with a couple of enhancements:
  • Bugfix to the "Check if already exists" logic, checking after replacing invalid characters.
  • Easier to customize; for example, I like using these instead:
    ReplacementChar="_"
    Folder=ws.SpecialFolders("MyDocuments") & "\My Downloaded Files"

Save the following code as a VBScript file, or overwrite your existing create_shortcut.vbs:
Set WSArgs=WScript.Arguments:Dim Name
if WSArgs.length<>1 Then WScript.Echo "Arguments Error!":WScript.Quit
Set fs=CreateObject("Scripting.FileSystemObject")
Set ws=CreateObject("WScript.Shell")
Set Rxp=New RegExp:Rxp.Global=1:Rxp.Pattern="[\\/:\*\?""<>\|]"
Set file=fs.OpenTextFile(WSArgs(0),1,vbFalse)
NameURL=file.ReadLine
file.Close
line=Split(NameURL, " ", 2)
URL=line(0)
Name=line(1)

ReplacementChar="-"
Folder=ws.SpecialFolders("Desktop")

Do
Name = Rxp.Replace(Name,ReplacementChar)
filename = Folder & "\" & Name & ".url"
If Not fs.FileExists(filename) Then Exit Do
Name=InputBox("A file with this name already exists, please type a different name:","Enter name:",Name)
If len(Name)=0 Then wscript.quit
Loop

Set SC=ws.CreateShortcut(filename)
SC.TargetPath=URL
SC.Save


For first-time readers, bind this script to Opera as per Ayush's original instructions:


In Opera, click Tools - Preferences - Advanced- Downloads - Click ADD
Type create/shortcut in MIME Type field and select Open with other application and select the VBS script as the application
Click OK > OK



Now use this UPDATED button, slightly different from the original:
button

Technical explanation:
The previous script used a line break between "title" and "URL", but line break characters now appear to be stripped before the MIME handler receives them. I don't think I've ever seen a space character in a URL, so I use that as the separator, and swapped the order in which they're passed to the script (now "URL" space "title"). I experimented with characters that are actually illegal in the formal spec for URLs, but all these seem to get stripped.


KNOWN BUGS
UTF-8 characters in a page's title seem to get mangled into pseudo-ASCII when turned into a filename. I'd welcome any VBS gurus who might know how to improve this.

HUGE THANKS to Ayush for the original implementation, saving me countless hours of research and frustration.

12. December 2009, 00:51:44

nynahs04

Posts: 57

I followed the latest instructions, but I can't get this to work in Opera 10.10.

Whenever I click the button I placed on my address bar, I get the following:

Error!
Invalid URL

The URL http://document.location=%27data:create/shortcut,%27+document.URL+' '+document.title; contains characters that are not valid in the location they are found.
The reason for their presence may be a mistyped URL, but the URL may also be an attempt to trick you into visiting a Web site which you might mistake for a site you trust.

thanks

20. August 2010, 07:14:17

DrGuz

Posts: 4

nynahs04, it works fine for me in Opera 10.10. Perhaps you are missing the "javascript:" portion of the URL.

The following line, or one like it, should be found in your standard toolbar (1).ini file, which under Windows XP is located in C:\Documents and Settings\(YOUR USERNAME)\Application Data\Opera\Opera\toolbar\

[Customize Toolbar Custom.content]
Button0, "Send to Desktop"="Go to page, "javascript:document.location='data:create/shortcut,'+document.URL+' '+document.title;", 1, "Send to Desktop", "Bookmark Unvisited""


Not your fault for missing that. Looks like the forum software here is safety-zealous, and strips off the "javascript:" prefix when generating a clickable link from the following forum code:
button
[ URL=opera:/button/Go%20to%20page,%20%22javascript:document.location='data:create/shortcut,'+document.URL+'%20'+document.title;%22,1,,%22Bookmark%20Unvisited%22 ]button[ /URL ]


UPDATED for UTF-8

Good news! By replacing FileSystemObject.OpenTextFile with ADODB.Stream.LoadFromFile, web page titles with non-ASCII characters are now correctly stored in the shortcut's file name.

Here is the revised create_shortcut.vbs in its entirety. With a couple more bonus tweaks since I last posted:
  • URL is used as title for pages with no title of their own
  • If file name is too long, or shortcut fails to create for some other reason, prompt is shown to edit the name.

Set WSArgs=WScript.Arguments:Dim Name
if WSArgs.length<>1 Then WScript.Echo "Arguments Error!":WScript.Quit
Set fs=CreateObject("Scripting.FileSystemObject")
Set ws=CreateObject("WScript.Shell")
Set Rxp=New RegExp:Rxp.Global=1:Rxp.Pattern="[\\/:\*\?""<>\|]"

Set objStream = CreateObject( "ADODB.Stream" )
objStream.Open
objStream.Type = 2  'adTypeText
objStream.Charset = "utf-8"
objStream.LoadFromFile WSArgs(0)
NameURL = objStream.ReadText
objStream.Close

line=Split(NameURL, " ", 2)
URL=line(0)
if UBound(line)<1 then
 Name=line(0)
else
 Name=line(1)
end if

ReplacementChar="_"
Folder=ws.SpecialFolders("Desktop")

Do
Name = Rxp.Replace(Name,ReplacementChar)
filename = Folder & "\" & Name & ".url"
If fs.FileExists(filename) Then
 Name=InputBox("A file with this name already exists, please type a different name:","Enter name:",Name)
else
 On Error Resume Next
 MakeShortcut
 If err.Number=0 Then Exit Do
 Name=InputBox("Could not create shortcut file, please type a different name:","Enter name:",Name)
end if
If len(Name)=0 Then Exit Do
Loop

Sub MakeShortcut
 Set SC=ws.CreateShortcut(filename)
 SC.TargetPath=URL
 SC.Save
End Sub

21. June 2012, 19:27:38

XP1

XP1

Posts: 869

I rewrote the script. I think that mine is the best one, but I would like other people to test it.

Create shortcut:
https://gist.github.com/2967901/

  1. Create a folder for storing the script.
  2. Go to the script on GitHub > Right click on "raw" > Save Linked Content As... > Save the WSF file to your folder.
  3. Opera > Settings > Preferences... > Advanced > Downloads > Add... > Under "MIME type", type "create/shortcut" > Select "Open with other application:" > Under "Open with other application:", select "Choose..." > Select the WSF file > OK > OK.
  4. Add this button.
  5. Drag the button to the toolbar.
Button source:
encodeURI('
opera:/button/Go to page, "javascript:(function () { \'use strict\'; var document = window.document; var location = window.location; var newline = \'%250D%250A\'; var title = document.title; var uri = location.href; location.assign(\'data:create/shortcut;charset=utf-8,\' + encodeURIComponent(encodeURIComponent((title.length > 0 ? title : uri)) + newline + encodeURIComponent(uri))); }());", 1, "Create shortcut", "External Hyperlink"
')


21. June 2012, 19:32:42

XP1

XP1

Posts: 869

I have also proposed a feature that allows you to save a shortcut file from the Save As dialog. See here if you are interested:

Save as shortcut (URL) file:
http://my.opera.com/community/forums/topic.dml?id=1443892

24. June 2012, 20:56:37

FaeGiN

Posts: 2

Hello there, I am coming back to Opera after leaving for years to Firefox!
I do miss a few addons and this function is one of them.
XP1, I just tested your script and I get a dialogue popup with the following:

---------------------------
Windows Script Host
---------------------------
Script:	C:\Program Files\Opera\scriptss\Create shortcut 1.00.wsf
Line:	1
Char:	3
Error:	Unexpected tag - expecting the tag 'job' or 'package' : html
Code:	800400C1
Source: 	Windows Script Host

---------------------------
OK   
---------------------------



Is it something I am doing wrong?
I followed the steps and that is what happens when I click the button...
Thanks.

24. June 2012, 22:15:04 (edited)

XP1

XP1

Posts: 869

Originally posted by FaeGiN:

XP1, I just tested your script and I get a dialogue popup with the following:

What Windows are you using? Try editing the WSF file by removing "<?xml version="1.0" encoding="utf-8"?>" at the top.

I'm guessing that you didn't save the actual file because you had automatic redirection turned off. Try re-saving the WSF file from GitHub. Instead of Saved Linked Content As..., click on the "raw" link. You should see the file. The first line should be "<?xml version="1.0" encoding="utf-8"?>". Ctrl + S to save.

26. June 2012, 12:52:49

FaeGiN

Posts: 2

Using Windows 7..
Aaah! you were correct. Saving it after opening it with the RAW link has worked. Nice! Better than all the others mate as it names them without hassling me.
Thanks a lot smile

16. July 2012, 20:09:27

DrGuz

Posts: 4

Works great for me. Thanks for the update, XP1!

TIP for novices: to store the shortcuts somewhere besides the desktop, find the following line near the bottom of the .WSF file,
var desktopPath = shell.specialFolders("Desktop");

and edit it as you see fit. Examples:
var desktopPath = shell.specialFolders("MyDocuments") + "/" + "My Downloaded Files";
var desktopPath = "E:/My Web Files/Shortcuts";

Forums » Opera for Windows/Mac/Linux » Desktop wish-list