问题
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