首页 > 系统相关 >再论Mac OS下如何将shell可执行文件转换成直接运行的APP?

再论Mac OS下如何将shell可执行文件转换成直接运行的APP?

时间:2022-12-15 13:35:04浏览次数:66  
标签:shell script APP 应用程序 your application Mac app

今天看见一个更加直接的转换方法,转载到这里来备份下,后续有需要可以实践一下,不过看其方法是比较完整和实用的。

fan'yi

是否曾经想到过让应用程序直接运行而不是多个shell命令?

仅仅将您的Shell脚本转换为Mac应用程序并像其他任何Mac应用程序一样使用它会不会很酷?

因此,让我们今天开始学习如何使用Shell脚本创建Mac应用程序。

在开始创建应用程序之前,我们将快速了解Mac中应用程序文件夹的结构:

对于Mac中的所有应用程序,最基本的文件夹结构如下所示。

Ever thought of having an application to run it directly instead of multiple shell commands?

And won’t it be cool to just convert your shell script into a Mac application and use it just like any other mac applications?

So let’s learn today to create mac app from a ​​shell script​​.

Before jumping into the application creation, we will quickly see how an application folder structure in Mac looks like:

The bare minimum folder structure is something like below that you will find for any applications in Mac.

(app-name).app
├── Contents
│   └── MacOS
│   └── (app-name)
└── Icon

现在开始吧。 我们的应用程序主要需要三件事:

可执行的Shell脚本,它将使您的Shell脚本成为应用程序。
您要使它作为应用程序的实际shell脚本。
将图标添加到您的应用程序。 (不是强制性的,但看起来像真正的应用程序一样酷)
让我们一步一步地完成这些步骤:

一个可执行的shell脚本,它将使您的shell脚本成为一个应用程序:

So now let’s get started. We need mainly three things for our application:

  1. An executable shell script which will make your shell script as an application.
  2. Your actual shell script to make it as an application.
  3. Add an icon to your application. (Not Mandatory but looks cool like real app)

Let’s walk through these steps one by one:

  1. An executable shell script which will make your shell script as an application:JavaScript
#!/usr/bin/env bash

APPNAME=${2:-$(basename "${1}" '.sh')};
DIR="${APPNAME}.app/Contents/MacOS";

if [ -a "${APPNAME}.app" ]; then
echo "${PWD}/${APPNAME}.app already exists. Provide some unique name if you want to create it anyway. ";
exit 1;
fi;

mkdir -p "${DIR}";
cp "${1}" "${DIR}/${APPNAME}";
chmod +x "${DIR}/${APPNAME}";

echo "${PWD}/$APPNAME.app";

使用上述脚本创建一个文件并将其保存在/ usr / local / bin中。
然后使用命令行/终端中的命令将上述文件设置为可执行文件:sudo chmod + x / usr / local / bin / appify
注意:

您可以给它指定任何名称,并且文件不需要扩展名。
作为参考,我们将其命名为“ appify”
我们会将文件保存在/ usr / local / bin中,以便我们可以直接调用“ appify”脚本。如果您想保存在用户名目录之类的其他位置,则必须使用完整路径(如“ / User /您的用户名/ appify”)调用脚本
使其成为应用程序的实际shell脚本:
现在,准备好具有.sh扩展名的脚本文件,并运行以下命令以使您将Shell脚本作为Mac应用程序使用。

  • Create a file with the above script and save it in /usr/local/bin .
  • Then make the above file as executable with the command from command line/Terminal: sudo chmod +x /usr/local/bin/appify
    Note:
  • You can give it any name and no extension is required for the file.
  • For reference, we will give it a name as ‘appify’
  • We are saving the file at /usr/local/bin  so that we can directly call ‘appify’ script. If you want to save at any other place like your username directory then you will have to call the script with its full path like ‘/User/your-username/appify’
  1. Your actual shell script to make it as an application:
  • Now have your script file with .sh extension ready and run the below command to make you shell script as a Mac application. JavaScript
appify your-shell-script.sh "Your App Name"
  1. Add an icon to your application:
    This one is very simple.
  • Just copy any image you want as the app icon.
  • Right-click your new application select “Get Info”.
  • Select the app icon on the top left corner by clicking it just once.
  • and then either hit ⌘ + V to paste it or go to ‘Edit’ from menu link and select paste.
  • With this, it will overwrite the default icon with your new icon.

Now your application is ready to use just like any other application.

 

I hope this post will help you learn how to create mac app from a shell script.

References:

转自:​​https://techtalkbook.com/create-mac-app-from-a-shell-script/​

标签:shell,script,APP,应用程序,your,application,Mac,app
From: https://blog.51cto.com/u_15797945/5939322

相关文章

  • 开发者的福音——APP热更新技术
    首先,热更新技术作为一种App软件开发者常用的更新方式,简而言之就是用户在下载安装APP之后,会有APP的即时更新。自从2017年苹果AppStore针对热更新的下架事件发生之后,诸多开发......
  • uniapp vue3下的代理转发不生效问题,亲测有效解决
    以前配置过vuevite的代理转发,没想到在uniapp的代理转发下翻车了,其实是一个很小的问题。调试过程中,尝试了webpack、vite等写法在根目录下创建了vite.config.jsvue.co......
  • uniapp 浏览器调试配置代理
    "h5":{"sdkConfigs":{"maps":{"qqmap":{"key":"SB5BZ-***********************-KVBUC"......
  • uniapp打包配置注意事项
    1.使用原生安卓api要在app权限配置中勾选对应功能  2.打包前要在app模块配置中勾选对应模块 ......
  • 安装官网免费的xshell
    首先访问xshell的官网https://www.xshell.com/zh/拉到最下面,有个家庭/学校免费,点进去拉到中间,有个表单,填一下名字和邮箱(邮箱必须要能接收到邮件),然后选择需要的软件......
  • Chapter 13 Pygame flappybird
    importpygameimportsysimportrandomclassBird(object):"""定义一个鸟类"""def__init__(self):"""定义初始化方法"""self.birdRect=......
  • App 实现的两类网络请求
    1.JavaHttpUrl 的实现如下:1.1Get请求{//显示进度finalProgressDialogprogressDialog=newProgressDialog(this);progressDialog.setTitle(......
  • 31-WebAPP服务器TomCat及优化
    Tomcat基础功能Tomcat服务器是一个免费的开放源代码的Web应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,Tomcat具有处理HTML静态......
  • PWN ORW 最短的shellcode(33字节!)
    前言:下面的rdx就是read(1,buf,n)中的n,这个值太大或者太小都没办法正常读。所以分两种大情况:orw:(64bit,34字节,针对需要调整rdx的情况:)shellcode=asm('''movedx,0x6761......
  • DailyRollingFileAppender 支持设置最大日志数量
    Log4j现在已经被大家熟知了,所有细节都可以在网上查到,Log4j支持Appender,其中DailyRollingFileAppender是被经常用到的Appender之一。最常用的Appender——RollingFileAppende......