使用 Platypus 从 perl 脚本创建 Mac OS X 应用程序 [英] Using Platypus to create Mac OS X applications from a perl script

查看:43
本文介绍了使用 Platypus 从 perl 脚本创建 Mac OS X 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

解决方案

文档对此很清楚,没有双向沟通;参见

Is it possible to get user input when using Platypus to build an application from a script?

I have a simple perl script. Which if I run from terminal, it asks for user input. But when I build an application file with Platypus, only the script's output is displayed.

解决方案

The documentation is clear on this, no bi-directional communication; see http://www.sveinbjorn.org/files/manpages/PlatypusDocumentation.html#812

That leaves you with a few workarounds;

  • Use and expect script to inject your inputs;
  • Update your script to take arguments, which is a feature supported by platypus;
  • If you need to add more dynamic information, consider using a TK dialog to query for user input;
  • On mac you can use an osascript to call a dialog with minimum code;

OSA Script Example

#!/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");

这篇关于使用 Platypus 从 perl 脚本创建 Mac OS X 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆