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

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

Trying to create a Status Menu app with Platypus.app

问题

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

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

  1. #!/usr/bin/perl
  2. # 如果没有参数,显示菜单
  3. if (!scalar(@ARGV)) {
  4. print "MENUITEMICON|AppIcon.icns|~/Desktop\n";
  5. print "MENUITEMICON|/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns|~/Desktop/3DProjects\n";
  6. print "MENUITEMICON|https://sveinbjorn.org/images/andlat.png|~/Desktop/2DProjects\n";
  7. print "SUBMENU|子菜单|项目1|项目2|项目3\n";
  8. } else {
  9. # 我们将菜单标题作为参数
  10. system("open $ARGV[0]");
  11. }

如果我使用相对路径作为菜单名称,这可以工作,但看起来不太好。如何使用 "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.

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

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" 等菜单并打开正确的文件夹?

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

  1. #!/usr/bin/perl
  2. my @menu = (
  3. {
  4. icon => 'AppIcon.icns',
  5. path => '~/Desktop',
  6. text => '打开桌面'
  7. },
  8. {
  9. icon => '/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns',
  10. path => '~/Desktop/2DProjects',
  11. text => '打开2D项目'
  12. }
  13. );
  14. # 如果没有参数,我们显示菜单
  15. if (!scalar(@ARGV)) {
  16. for my $item (@menu) {
  17. print "MENUITEMICON|" . $item->{icon} . "|" . $item->{text} . "\n";
  18. }
  19. }
  20. else {
  21. # 我们将菜单标题作为参数传递
  22. my $path;
  23. my $text = $ARGV[0];
  24. for my $item (@menu) {
  25. if ($item->{text} eq $text){
  26. $path = $item->{path};
  27. last;
  28. }
  29. }
  30. system("open $path");
  31. }

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

英文:

> 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:

  1. #!/usr/bin/perl
  2. my @menu = (
  3. {
  4. icon => 'AppIcon.icns',
  5. path => '~/Desktop',
  6. text => 'Open Desktop'
  7. },
  8. {
  9. icon => '/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns',
  10. path => '~/Desktop/2DProjects',
  11. text => 'Open 2DProjects'
  12. }
  13. );
  14. # If 0 arguments, we show menu
  15. if (!scalar(@ARGV)) {
  16. for my $item (@menu) {
  17. print "MENUITEMICON|" . $item->{icon} . "|" . $item->{text} . "\n";
  18. }
  19. }
  20. else {
  21. # We get the menu title as an argument
  22. my $path;
  23. my $text = $ARGV[0];
  24. for my $item (@menu) {
  25. if ($item->{text} eq $text){
  26. $path = $item->{path};
  27. last;
  28. }
  29. }
  30. system("open $path");
  31. }

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:

确定