Created
June 21, 2012 19:16
-
-
Save XP1/2967901 to your computer and use it in GitHub Desktop.
Create shortcut: Creates a shortcut on the desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<package> | |
<job id="createShortcut"> | |
<?job error="false" debug="false"?> | |
<script> | |
//<![CDATA[ | |
/* | |
* Copyright 2012 XP1 | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
/*jslint browser: true, vars: true, white: true, maxerr: 50, indent: 4 */ | |
(function (script, ActiveXObject, shell, fileSystem) | |
{ | |
"use strict"; | |
function sanitizeFilename(filename, replacement) | |
{ | |
filename = filename.replace(/^(AUX|CLOCK\$|COM[0-9]|CON|LPT[0-9]|NUL|PRN)(\..+)?$|[\x00-\x1F\/\\:*?"<>|]/gm, replacement); | |
var length = filename.length; | |
if (length > 220) | |
{ | |
filename = filename.substring(0, 220) + "..."; | |
} | |
else if (length <= 0) | |
{ | |
filename = "Untitled"; | |
} | |
return filename; | |
} | |
function createShortcut(path, title, uri) | |
{ | |
var filename = title + ".url"; | |
var i = 2; | |
while (fileSystem.fileExists(path + "/" + filename)) | |
{ | |
filename = title + " (" + i + ").url"; | |
i += 1; | |
} | |
var textStream = new ActiveXObject("ADODB.Stream"); | |
textStream.type = 2; | |
textStream.mode = 3; | |
textStream.charSet = "utf-8"; | |
textStream.open(); | |
textStream.writeText("[InternetShortcut]", 1); | |
textStream.writeText("URL=" + uri, 1); | |
textStream.position = 3; | |
var binaryStream = new ActiveXObject("ADODB.Stream"); | |
binaryStream.type = 1; | |
binaryStream.mode = 3; | |
binaryStream.open(); | |
textStream.copyTo(binaryStream); | |
textStream.close(); | |
binaryStream.saveToFile(path + "/" + filename); | |
binaryStream.close(); | |
} | |
function initialize() | |
{ | |
var scriptArguments = script.arguments; | |
if (scriptArguments.length <= 0) | |
{ | |
throw new Error("No arguments supplied."); | |
} | |
var path = scriptArguments.item(0); | |
var file = fileSystem.openTextFile(path, 1); | |
var text = decodeURIComponent(file.readAll()); | |
file.close(); | |
fileSystem.deleteFile(path, true); | |
var lines = text.split(/\r\n|\n|\r/g); | |
var title = sanitizeFilename(lines[0], "_"); | |
var uri = lines[1]; | |
var desktopPath = shell.specialFolders("Desktop"); | |
createShortcut(desktopPath, title, uri); | |
} | |
initialize(); | |
script.quit(); | |
}(this.WScript, this.ActiveXObject, new this.ActiveXObject("WScript.Shell"), new this.ActiveXObject("Scripting.FileSystemObject"))); | |
//]]> | |
</script> | |
</job> | |
</package> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I posted this script in this thread:
Saving a website shortcut to the desktop:
http://my.opera.com/community/forums/topic.dml?id=193574
Related threads:
Problem shortcut on desktop:
http://my.opera.com/community/forums/topic.dml?id=1436812
Drag and drop of URL on windows:
http://my.opera.com/community/forums/topic.dml?id=652052
dragging and dropping a link from the address bar doesn't work:
http://my.opera.com/community/forums/topic.dml?id=668542
URL Drag And Drop:
http://my.opera.com/community/forums/topic.dml?id=1433402