尝试使用Platypus.app创建一个状态菜单应用程序。

huangapple go评论65阅读模式
英文:

Trying to create a Status Menu app with Platypus.app

问题

我正在尝试创建一个基本的状态菜单应用程序,使用 Platypus.app

我觉得我快要成功了,但我却无法实现,并且这已经困扰我一个星期了。

#!/usr/bin/perl

# 如果没有参数,显示菜单
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|子菜单|项目1|项目2|项目3\n";
    
} else {
    # 我们将菜单标题作为参数
    
    system("open  $ARGV[0]");
}

如果我使用相对路径作为菜单名称,这可以工作,但看起来不太好。如何使用 "Open Desktop"、"Open 3DProjects" 等作为菜单,并使其打开正确的文件夹呢?

另外,是否可以为子菜单项添加图标?

英文:

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?

答案1

得分: 1

> 我如何使用"Open Desktop"、"Open 2DProjects" 等菜单并打开正确的文件夹?

你可以尝试在脚本中保存绝对路径,像这样:

#!/usr/bin/perl

my @menu = (
    {
        icon => 'AppIcon.icns',
        path => '~/Desktop',
        text => '打开桌面'
    },
    {
        icon => '/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns',
        path => '~/Desktop/2DProjects',
        text => '打开2D项目'
    }
);

# 如果没有参数,我们显示菜单
if (!scalar(@ARGV)) {
    for my $item (@menu) {
        print "MENUITEMICON|" . $item->{icon} . "|" . $item->{text} . "\n";
    }
}
else {
    # 我们将菜单标题作为参数传递
    my $path;
    my $text = $ARGV[0];
    for my $item (@menu) {
        if ($item->{text} eq $text){
            $path = $item->{path};
            last;
        }
    }
    system("open $path");
}

请注意,我已经将菜单文本从英文翻译成了中文,以便更好地理解。

英文:

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

huangapple
  • 本文由 发表于 2023年7月3日 23:21:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76606126.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定