2

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.

Mohammad Jumah
  • 405
  • 1
  • 4
  • 14

1 Answers1

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

enter image description here

harvey
  • 2,945
  • 9
  • 10
  • Thanks, very helpful comment. I have installed TK modules for perl, and XQuartz on my Mac. This enabled my basic perl script to get user input using using a GUI interface, which was my attempt. – Mohammad Jumah Nov 10 '15 at 15:54