有没有办法用adobe air生成快捷方式文件?

时间:2011-12-01 18:09:55

标签: actionscript-3 flex air filesystems adobe

下午好,
我想创建一个应用程序,可以创建文件夹和文件系统中的文件夹的快捷方式。用户将单击一个按钮,它将在桌面上放置一个文件夹,其中包含文件的快捷方式,如// server / folder1 / folder2。您可以在adobe air中创建一个包含代码的桌面快捷方式吗?你会怎么做?你如何创建一个文件夹?我一直认为这应该很容易,但我一直都想念它。
谢谢你的帮助,抱歉给你带来了麻烦 贾斯汀

4 个答案:

答案 0 :(得分:3)

如果您的部署配置文件是Extended Desktop,您可以使用NativeProcess以及一些可以与应用打包在一起的简单脚本。这种方法需要在每个操作系统的基础上处理功能,这需要一些工作和广泛的测试。但是,我想至少分享一个我验证确实有效的方案。下面是一个我把它放在一起的测试用例:

测试用例:Windows 7

即使是Adobe documentation says that it prevents execution of .bat files,显然也不会阻止执行Windows脚本主机: wscript.exe 。这意味着您可以执行任何JScript或VBScript文件。这就是您用来编写命令以在Windows中创建快捷方式的原因(因为Windows没有命令行命令来创建快捷方式)。

这是一个创建快捷命令的简单脚本,我在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();

如果您将此应用程序打包到名为 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);

  }
}

如果想在桌面上创建应用程序存储目录的快捷方式,则以下内容就足够了:

var targetLocation:File = File.applicationStorageDirectory;
var shortcutLocation:File = File.desktopDirectory.resolvePath("Shortcut to My AIR App Storage");

createShortcut(targetLocation, shortcutLocation);

显然,要处理不同的操作系统环境还有很多工作要做,但这至少是一个步骤。

答案 1 :(得分:1)

答案 2 :(得分:0)

Air不允许您本地创建快捷方式。这是一个适用于Windows的解决方法[可以在Mac上运行但我没有机器可以测试]。

使用Air,创建包含以下纯文本的文件

[InternetShortcut]
URL=C:\path-to-folder-or-file

path-to-folder-or-file替换为您的文件夹/文件名

将文件另存为test.url

Windows将此文件识别为快捷方式。

答案 3 :(得分:0)

可以强制Adobe Air在Mac上创建符号链接,其他有用的东西。以下是我的表现方式:

您需要AIRAliases.js - 修订版:2.5

在application.xml中添加:

<!-- Enables NativeProcess -->
<supportedProfiles>extendedDesktop desktop</supportedProfiles>

在Air app 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));
};

更改传递给NativeProcess的命令和参数的语法,您也应该能够在Windows上获得真正的快捷方式。