【问题标题】:Using Platypus to create Mac OS X applications from a perl script使用 Platypus 从 perl 脚本创建 Mac OS X 应用程序
【发布时间】:2015-11-09 02:25:58
【问题描述】:

使用 Platypus 从脚本构建应用程序时是否可以获取用户输入?

我有一个简单的 perl 脚本。如果我从终端运行,它会要求用户输入。但是当我使用 Platypus 构建应用程序文件时,只显示脚本的输出。

【问题讨论】:

    标签: perl platypus


    【解决方案1】:

    文档对此很清楚,没有双向通信;见http://www.sveinbjorn.org/files/manpages/PlatypusDocumentation.html#812

    这给您留下了一些解决方法;

    • Use and expect script 注入您的输入;
    • 更新您的脚本以接受参数,这是 platypus 支持的一项功能;
    • 如果需要添加更多动态信息,可以考虑使用TK dialog查询用户输入;
    • 在 mac 上,您可以使用 osascript 以最少的代码调用对话框;

    OSA 脚本示例

    #!/usr/bin/env perl
    
    use strict;
    
    sub osascript($) { system 'osascript', map { ('-e', $_) } split(/\n/, $_[0]); }
    
    sub dialog {
      my ($text, $default) = @_;
      osascript(qq{
            tell app "System Events"
                text returned of (display dialog "$text" default answer "$default" buttons {"OK"} default button 1 with title "$(basename $0)")
            end tell
      });
    }
    
    my $result = dialog("Life, the universe and everything?", "42");
    

    【讨论】:

    • 谢谢,非常有帮助的评论。我已经在我的 Mac 上安装了 perl 和 XQuartz 的 TK 模块。这使我的基本 perl 脚本能够使用 GUI 界面获取用户输入,这是我的尝试。
    猜你喜欢
    • 1970-01-01
    • 2011-11-07
    • 1970-01-01
    • 1970-01-01
    • 2013-04-07
    • 1970-01-01
    • 2012-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多