Search code examples
macosperlplatypus

Trying to create a Status Menu app with Platypus.app


I'm trying to create a basic status menu app with Platypus.app

I feel I'm almost there but I can't get there and it's been puzzling for a week now.

#!/usr/bin/perl

# If 0 arguments, we show menu
if (!scalar(@ARGV)) {
    print "MENUITEMICON|AppIcon.icns|~/Desktop\n";
    print "MENUITEMICON|/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns|~/Desktop/3DProjects\n";
    print "MENUITEMICON|https://sveinbjorn.org/images/andlat.png|~/Desktop/2DProjects\n";
    print "SUBMENU|Submenu|Item 1|Item 2|Item 3\n";
    
} else {
    # We get the menu title as an argument
    
    
    system("open  $ARGV[0]");
}

This works if I use the relative path as the menu name, but that doesn't look good. How do I use Open Desktop, Open 3DProjects etc as the menu and have it open the correct folder?

Also, is it possible to add an icon to the submenu items?


Solution

  • How do I use Open Desktop, Open 3DProjects etc as the menu and have it open the correct folder?

    Can you try save the absolute path in the script like this:

    #!/usr/bin/perl
    
    my @menu = (
        {
            icon => 'AppIcon.icns',
            path => '~/Desktop',
            text => 'Open Desktop'
        },
        {
            icon => '/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns',
            path => '~/Desktop/2DProjects',
            text => 'Open 2DProjects'
        }
    );
    
    # If 0 arguments, we show menu
    if (!scalar(@ARGV)) {
        for my $item (@menu) {
            print "MENUITEMICON|" . $item->{icon} . "|" . $item->{text} . "\n";
        }
    }
    else {
        # We get the menu title as an argument
        my $path;
        my $text = $ARGV[0];
        for my $item (@menu) {
            if ($item->{text} eq $text){
                $path = $item->{path};
                last;
            }
        }
        system("open $path");
    }