Using Platypus to create Mac OS X applications from a perl script

你说的曾经没有我的故事 提交于 2019-12-11 00:47:26

问题


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.


回答1:


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");



来源:https://stackoverflow.com/questions/33601580/using-platypus-to-create-mac-os-x-applications-from-a-perl-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!