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

发布于 2024-12-19 05:05:35 字数 210 浏览 1 评论 0原文

下午好,
我想创建一个可以在文件系统中创建文件夹和文件夹快捷方式的应用程序。用户将单击一个按钮,它会在桌面上放置一个文件夹,该文件夹具有指向 //server/folder1/folder2 等文件的快捷方式 您可以在 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? 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

你的心境我的脸 2024-12-26 05:05:35

如果您的部署配置文件是扩展桌面,您也许能够使用NativeProcess 以及一些您可以打包的简单脚本与您的应用程序。这种方法需要在每个操作系统的基础上处理功能,这需要一些工作和广泛的测试。然而,我至少想分享一个我验证确实有效的场景。下面是我整理的一个测试用例:

测试用例:Windows 7

即使 Adobe 文档表示它会阻止执行.bat 文件,显然它不会阻止执行 Windows 脚本宿主:wscript.exe。这意味着您可以执行任何 JScript 或 VBScript 文件。这就是您在 Windows 中编写命令来创建快捷方式的方法(因为 Windows 没有命令行命令来创建快捷方式)。

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

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

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. This approach would entail handling the functionality on a per OS basis, which would take some work and extensive testing. However, I wanted to at least share a scenario that I verified does work. Below is a test case that I threw together:

Test Case: Windows 7

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. This means you can execute any JScript or VBScript files. 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).

Here's a simple script to create a shortcut command, which I found on giannistsakiris.com, (converted to 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:

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.

只是在用心讲痛 2024-12-26 05:05:35

As far as I know, File class does not allow the creation of symbolic links. But you can create directories with createDirectory(): http://help.adobe.com/en_US/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/

ぃ弥猫深巷。 2024-12-26 05:05:35

Air 本身不允许您创建快捷方式。这是适用于 Windows 的解决方法 [可能适用于 Mac,但我没有机器可以测试]。

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

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

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

将文件另存为 test.url

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

Air doesnt let you create shortcuts natively. Here's a workaround that works with Windows [may work on Mac but I don't have a machine to test].

Using Air, create a file that contains the following plain text

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

Replace path-to-folder-or-file with your folder/file name

Save the file as test.url

Windows recognizes this file as a shortcut.

玩套路吗 2024-12-26 05:05:35

可以强制 Adob​​e Air 在 Mac 上创建符号链接和其他有用的东西。我是这样做的:

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

在 application.xml 中添加:

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

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

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

It is possible to coerce Adobe Air into creating symbolic links, other useful things, on a Mac. Here's how I did it:

You will need AIRAliases.js - Revision: 2.5

In the application.xml add:

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

In the 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));
};

Altering the syntax of the command and parameters passed to NativeProcess you should be able to get real shortcuts on Windows too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文