[英]Is there a way generate a shortcut file with adobe air?
Good afternoon, 下午好,
I would like create a application that can can create folders and short cuts to folders in the file system. 我想创建一个可以在文件系统中创建文件夹和文件夹快捷方式的应用程序。 The user will click a button and it will put a folder on there desktop that has short cuts to files like //server/folder1/folder2 Can you create a desktop shortcut with code in adobe air?
用户将单击一个按钮,它将在该桌面上放置一个文件夹,该文件夹具有一个对// server / folder1 / folder2之类的文件的快捷方式。是否可以在Adobe Air中使用代码创建桌面快捷方式? How would you do that?
你会怎么做? How do you create a folder?
如何创建文件夹? I keep thinking this should be easy but i keep missing it.
我一直认为这应该很容易,但是我一直很想念它。
Thank you for your help sorry for the trouble, 谢谢您的帮助,对不起,
Justin 贾斯汀
If your deployment profile is Extended Desktop , you may be able to use NativeProcess and some simple scripts that you could package with your app. 如果您的部署配置文件是Extended Desktop ,则可以使用NativeProcess以及可以与应用程序打包在一起的一些简单脚本。 This approach would entail handling the functionality on a per OS basis, which would take some work and extensive testing.
这种方法需要在每个OS的基础上处理功能,这将需要一些工作和广泛的测试。 However, I wanted to at least share a scenario that I verified does work.
但是,我至少想分享一个我验证确实可行的方案。 Below is a test case that I threw together:
以下是我一起提出的一个测试案例:
Even though the Adobe documentation says that it prevents execution of .bat files , apparently it doesn't prevent one from executing the Windows Scripting Host: wscript.exe . 即使Adobe文档说它阻止了.bat文件的执行 ,但显然它并没有阻止它执行Windows脚本宿主: wscript.exe 。 This means you can execute any JScript or VBScript files.
这意味着您可以执行任何JScript或VBScript文件。 And this is what you would use to write a command to create a shortcut in Windows (since Windows doesn't have a commandline command to create shortcuts otherwise).
这就是您用来在Windows中编写用于创建快捷方式的命令的方法(因为Windows没有用于创建快捷方式的命令行命令)。
Here's a simple script to create a shortcut command, which I found on giannistsakiris.com , (converted to JScript): 这是一个创建快捷方式命令的简单脚本,我在giannistsakiris.com上找到了它 (转换为JScript):
// File: mkshortcut.js
var WshShell = new ActiveXObject("WScript.Shell");
var oShellLink = WshShell.CreateShortcut(WScript.Arguments.Named("shortcut") + ".lnk");
oShellLink.TargetPath = WScript.Arguments.Named("target");
oShellLink.WindowStyle = 1;
oShellLink.Save();
If you package this in your application in a folder named utils , you could write a function to create a shortcut like so: 如果将此文件打包在应用程序中的utils文件夹中,则可以编写一个函数来创建快捷方式,如下所示:
public function createShortcut(target:File, shortcut:File):void {
if (NativeProcess.isSupported) { // Note: this is only true under extendedDesktop profile
var shortcutInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
// Location of the Windows Scripting Host executable
shortcutInfo.executable = new File("C:/Windows/System32/wscript.exe");
// Argument 1: script to execute
shortcutInfo.arguments.push( File.applicationDirectory.resolvePath("utils/mkshortcut.js").nativePath);
// Argument 2: target
shortcutInfo.arguments.push("/target:" + target.nativePath);
// Argument 3: shortcut
shortcutInfo.arguments.push("/shortcut:" + shortcut.nativePath);
var mkShortcutProcess = new NativeProcess();
mkShortcutProcess.start(shortcutInfo);
}
}
If one wanted to create a shortcut to the Application Storage Directory on the Desktop, the following would suffice: 如果要在桌面上创建到应用程序存储目录的快捷方式,则满足以下条件:
var targetLocation:File = File.applicationStorageDirectory;
var shortcutLocation:File = File.desktopDirectory.resolvePath("Shortcut to My AIR App Storage");
createShortcut(targetLocation, shortcutLocation);
Obviously there's a lot of work to be done to handle different OS environments, but this is at least a step. 显然,要处理不同的OS环境,需要做很多工作,但这至少是一个步骤。
As far as I know, File class does not allow the creation of symbolic links. 据我所知,File类不允许创建符号链接。 But you can create directories with
createDirectory()
: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/File.html#createDirectory%28%29 但是您可以使用
createDirectory()
创建目录: http : //help.adobe.com/zh_CN/FlashPlatform/reference/actionscript/3/flash/filesystem/File.html#createDirectory%28%29
Check if this can be useful: http://www.mikechambers.com/blog/2008/01/17/commandproxy-net-air-integration-proof-of-concept/ 检查这是否有用: http : //www.mikechambers.com/blog/2008/01/17/commandproxy-net-air-integration-proof-of-concept/
Air doesnt let you create shortcuts natively. Air不允许您本地创建快捷方式。 Here's a workaround that works with Windows [may work on Mac but I don't have a machine to test].
这是一种适用于Windows的解决方法(可能在Mac上可以使用,但我没有要测试的机器)。
Using Air, create a file that contains the following plain text 使用Air,创建一个包含以下纯文本的文件
[InternetShortcut]
URL=C:\path-to-folder-or-file
Replace path-to-folder-or-file
with your folder/file name 将
path-to-folder-or-file
替换path-to-folder-or-file
您的文件夹/文件名
Save the file as test.url
将文件另存为
test.url
Windows recognizes this file as a shortcut. Windows将此文件识别为快捷方式。
It is possible to coerce Adobe Air into creating symbolic links, other useful things, on a Mac. 在Mac上,可以强迫Adobe Air创建符号链接和其他有用的东西。 Here's how I did it:
这是我的操作方式:
You will need AIRAliases.js - Revision: 2.5 您将需要AIRAliases.js-修订:2.5
In the application.xml add: 在application.xml中添加:
<!-- Enables NativeProcess -->
<supportedProfiles>extendedDesktop desktop</supportedProfiles>
In the Air app JavaScript: 在Air应用程序JavaScript中:
// A familiar console logger
var console = {
'log' : function(msg){air.Introspector.Console.log(msg)}
};
if (air.NativeProcess.isSupported) {
var cmdFile = air.File.documentsDirectory.resolvePath("/bin/ln");
if (cmdFile.exists) {
var nativeProcessStartupInfo = new air.NativeProcessStartupInfo();
var processArgs = new air.Vector["<String>"]();
nativeProcessStartupInfo.executable = cmdFile;
processArgs.push("-s");
processArgs.push("< source file path >");
processArgs.push("< link file path >");
nativeProcessStartupInfo.arguments = processArgs;
nativeProcess = new air.NativeProcess();
nativeProcess.addEventListener(air.NativeProcessExitEvent.EXIT, onProcessExit);
nativeProcess.addEventListener(air.ProgressEvent.STANDARD_OUTPUT_DATA, onProcessOutput);
nativeProcess.addEventListener(air.ProgressEvent.STANDARD_ERROR_DATA, onProcessError);
nativeProcess.start(nativeProcessStartupInfo);
} else {
console.log("Can't find cmdFile");
}
} else {
console.log("Not Supported");
}
function onProcessExit(event) {
var result = event.exitCode;
console.log("Exit Code: "+result);
};
function onProcessOutput() {
console.log("Output: "+nativeProcess.standardOutput.readUTFBytes(nativeProcess.standardOutput.bytesAvailable));
};
function onProcessError() {
console.log("Error: "+nativeProcess.standardError.readUTFBytes(nativeProcess.standardError.bytesAvailable));
};
Altering the syntax of the command and parameters passed to NativeProcess you should be able to get real shortcuts on Windows too. 更改传递给NativeProcess的命令和参数的语法,您也应该能够在Windows上获得真正的快捷方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.