Menu
MacOS X Mojave 10.14 (Hosted maxOS) macOS X High Sierra 10.13 (Hosted macOS High Sierra) Microsoft-hosted agentsの制限事項は以下の点。 パブリックプロジェクト且つ、パブリックリポジトリのjobは、360分(6時間)まで; プライベートプロジェクトまたは、プライベートリポジトリのjobは60.
makeapp.rb
#!/usr/bin/env ruby |
# cf. http://bit.ly/2raKfLZ |
# makeapp - スクリプトをMacのアプリケーションにする |
ifARGV.length != 2 |
abort('Usage: makeapp foo.rb Foo.app') |
end |
scriptname=ARGV[0] |
appname=ARGV[1] |
system('mkdir -p #{appname}/Contents/MacOS') |
system('mkdir -p #{appname}/Contents/Resources') |
open('#{appname}/Contents/Info.plist','w')do |f| |
f.puts<<-'EOD' |
<?xml version='1.0' encoding='UTF-8'?> |
<!DOCTYPE plist PUBLIC '-//Apple Computer//DTD PLIST 1.0//EN' 'http://www.apple.com/DTDs/PropertyList-1.0.dtd'> |
<plist version='1.0'> |
<dict> |
<key>CFBundleExecutable</key> |
<string>#{scriptname}</string> |
</dict> |
</plist> |
EOD |
end |
system('cp #{scriptname}#{appname}/Contents/MacOS/') |
system('chmod +x #{appname}/Contents/MacOS/#{scriptname}') |
commented May 30, 2017
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment
Another way to create Finder-clickable shell scripts | 30 comments | Create New Account
Click here to return to the 'Another way to create Finder-clickable shell scripts' hint |
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Another way to create Finder-clickable shell scripts
Another way to create Finder-clickable shell scripts
There's a better way.
Let's say you have a shell script called foo.sh. Do this:
mkdir -p foo.app/Contents/MacOS
mv foo.sh foo.app/Contents/MacOS/foo
chmod +x foo.app/Contents/MacOS/foo
Done. Double-click foo.app (which the Finder shows you as simply 'foo') and your shell script runs. No developer tools required, and it doesn't depend on fragile metadata like this hint does.
Let's say you have a shell script called foo.sh. Do this:
mkdir -p foo.app/Contents/MacOS
mv foo.sh foo.app/Contents/MacOS/foo
chmod +x foo.app/Contents/MacOS/foo
Done. Double-click foo.app (which the Finder shows you as simply 'foo') and your shell script runs. No developer tools required, and it doesn't depend on fragile metadata like this hint does.
Another way to create Finder-clickable shell scripts
I tried this one, cause I like it better than the previous hint -- I can add a nice icon and other frills! -- but this failed for me..
The Finder decided that my foo.app was a Classic App, but didn't bring up the Classic Environment. My script is woefully simple -- it simply calls a Terminal-based executable -- which now launched in the background, with no user interaction..
So I'll stick to the following, as in the older hint, for now -- just change your
Chmod X Foo.app Contents Macos Download
foo.sh
to
foo.command
and presto -- auto-launch of the Terminal, and auto-run of the script therein, complete with user interaction.
---
Ted Thibodeau Jr -- Technical Evangelist -- OpenLink Software
Ted Thibodeau Jr -- Technical Evangelist -- OpenLink Software
Another way to create Finder-clickable shell scripts
You also have to create a file foo.app/Contents/Info.plist containing keys identifying the name of the executable. In this exampe, it would contain:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist SYSTEM 'file://localhost/System/Library/DTDs/PropertyList.dtd'>
<plist version='0.9'>
<dict>
<key>CFBundleExecutable</key>
<string>foo</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.3.0</string>
</dict>
</plist>
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist SYSTEM 'file://localhost/System/Library/DTDs/PropertyList.dtd'>
<plist version='0.9'>
<dict>
<key>CFBundleExecutable</key>
<string>foo</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.3.0</string>
</dict>
</plist>
![Chmod X Foo.app Contents Macos Chmod X Foo.app Contents Macos](/uploads/1/2/7/3/127303964/351351501.png)
Another way to create Finder-clickable shell scripts
Nope. You don't actually have to do this.
When you double-click on foo.app, the Finder looks for a file foo.app/Contents/Info.plist. Not finding it, it looks for an executable file with the same name as the base name of the application package: foo.app/Contents/MacOS/foo. It then exec's it.
The only trick is that you have to be sure the file is executable.
When you double-click on foo.app, the Finder looks for a file foo.app/Contents/Info.plist. Not finding it, it looks for an executable file with the same name as the base name of the application package: foo.app/Contents/MacOS/foo. It then exec's it.
The only trick is that you have to be sure the file is executable.
Another way to create Finder-clickable shell scripts
Neat hint!
But to make it work, I had to make an Info.plist file in the bundle, which must contain the usual xml headers plus the following key at minimum:
Apple's developer documentation about keys used in the bundles instruct not to use a file name extension for the actual program -- and after dropping the extension the shell script shows as an application inside the bundle too.
![Macos Macos](/uploads/1/2/7/3/127303964/474944843.png)
I have been looking for a way to make a 'droplet' from shell script, so I could drop files into the shell script which would get the dropped files as arguments.
Editing the CFBundleDocumentTypes key in Info.plist didn't seem to achieve this. Does anyone know how this could be done?
This might be a great way to package Python programs too!
I use applescript to accomplish this. Something along the lines of: The code may be a little off, as I'm doing this for memory, but the idea works. I use it in my UnButton app, which you can get the source code for at http://www.freefallsoftware.com/products.html---
--
duo
--
duo
Another way to create Finder-clickable shell scripts
So you're saying if we set the creator to APPL it's always run as root? Is that a security risk? Say I am a limited user, I download setFile, and create a shellscript called Terminate.sh, and the base code is:
rm -r /
And set the creator to APPL, I can basically destroy the data on the root drive by double clicking the file I created?
That's bad news if it's true
rm -r /
And set the creator to APPL, I can basically destroy the data on the root drive by double clicking the file I created?
That's bad news if it's true
Another way to create Finder-clickable shell scripts
I'm pretty sure he means it's run from the root directory, not as root. That's why he mentions absolute paths..
e.g. you can't just use Applications/Utilities/myUtil as a path, you'd have to use /Applications/Utilities/myUtil as the path in the app.
In other words, if you run a shell script like this it always assumes it's being run from /
e.g. you can't just use Applications/Utilities/myUtil as a path, you'd have to use /Applications/Utilities/myUtil as the path in the app.
In other words, if you run a shell script like this it always assumes it's being run from /
Another way to create Finder-clickable shell scripts
No, it's an unfortunate overloading of the word 'root'. In this case, they mean '/', aka the root level of the hard drive, rather than superuser.
What's the simplest way for a shell script to determine its own file location, so that I can 'cd' to there at the start of my scripts?
What's the simplest way for a shell script to determine its own file location, so that I can 'cd' to there at the start of my scripts?
Another way to create Finder-clickable shell scripts
You don't need to know, just do a cd with an absolute path.
Another way to create Finder-clickable shell scripts
The key point is that the path must be absolute. /Users/username/Desktop instead of Desktop and so on.
cd
won't help you in a shell script. You must still use absolute paths in the rest of the script. What can save you though is using variables.So if you're going to do a lot of things in a specific diretory instead of having:
ls /Users/username/sometempdir >> /var/logs/savedfiles.txt
rm /Users/username/sometempdir/*
You can do it like this:
export tempdir=/Users/username/sometempdir
ls $tempdir >> /var/logs/savedfiles.txt
rm $tempdir/*
Remember to include
#!/bin/sh
in the top of the shell script to tell that it should be executed by Bash. I'm not sure other shells support the export command.
Another way to create Finder-clickable shell scripts
Oh yeah.. if you want to use the script in my example, I would recommend: #!/bin/sh
export tempdir=/Users/username/sometempdir
export date=$(date +'%Y%m%d-%H%M') ls $tempdir >> /var/logs/savedfiles.txt
tar czf /Users/username/$date.tgz $tempdir rm $tempdir/*
export tempdir=/Users/username/sometempdir
export date=$(date +'%Y%m%d-%H%M') ls $tempdir >> /var/logs/savedfiles.txt
tar czf /Users/username/$date.tgz $tempdir rm $tempdir/*
this script creates a tar-gzipped file with the date as the name in the home directory of the user username. It appends the list of files to the file /var/logs/savedfiles.txt and removes the files from the original directory
Another way to create Finder-clickable shell scripts
of course you can use cd in a shell script, its just easier to mess up that way.. it is a shell after all! :-D
---
Pell
---
Pell
The output of dirname $0 will tell you the directory in which the shell script is located. If your shell script wants to cd to the directory that contains the script itself, it should say
Another way to create Finder-clickable shell scripts
My fault. I misread run in root as run as root. My Bad
Another way to create Finder-clickable shell scripts
Another option:
For scripts that print output or require you to respond to them there is a neat solution:
Go to the terminal, set up the window settings (colour, position, size etc..) and go to File > Save and put the file where you want. It saves the settings as a '.term' file.
When you double click the .term file, it opens a new terminal window with the settings you chose. Edit the file in your favourite app (TextEdit is fine) and find the line:
<key>ExecutionString</key>
<string></string>
Insert the command (full path is probably safest) in between <string> and </string> and save the file.
This is great for putting a group of commands in (separated by semi colons) and for making the terminal window unique to that command!!
For scripts that print output or require you to respond to them there is a neat solution:
Go to the terminal, set up the window settings (colour, position, size etc..) and go to File > Save and put the file where you want. It saves the settings as a '.term' file.
When you double click the .term file, it opens a new terminal window with the settings you chose. Edit the file in your favourite app (TextEdit is fine) and find the line:
<key>ExecutionString</key>
<string></string>
Insert the command (full path is probably safest) in between <string> and </string> and save the file.
This is great for putting a group of commands in (separated by semi colons) and for making the terminal window unique to that command!!
Another way to create Finder-clickable shell scripts
There is a freeware program called Platypus that makes a shell script into a Finder-clickable app. The program also has options for using Perl, Python, Ruby and AppleScript (why would you need a program that makes an AppleScript executable? : )
Platypus Launch the program, choose your options, and create an applet. Easy.
Jul 06, 2020 The Fl. development team has released v4.0.16 of Flmsg. Flmsg is a simple forms management editor for the amateur radio supported standard message formats. Form data can be transferred between computers either using standard internet email or via radio frequency broadcasts typically made by an amateur radio operator on your behalf. Mac ham radio programming software.
I use this application to run a shell script that compiles statistics of my Jedi Knight II game server. :)
What about file input? It would be great if I could drop some text files on a such an application, but Platypus doesn't support it.
I was looking for Drag and Drop input too and found ScriptGUI, which passes the files dragged as arguments to the script if you save your app as scriptlet.
Apologies if this has been mentioned above, but I didn't see it: DropScript (search on versiontracker) does what the hint claims to do, but reliably, freely (in whatever sense you wish), and allows files to be dragged onto the resulting icon (unlike platypus, at least for now). It's been available since 2001.
Cheers,
Paul
Cheers,
Paul
<shameless plug>
Please have a look at my TurboTool (www.turbotool.de) which features D&D input very well and was created with those applications in mind
</shameless plug>
Please have a look at my TurboTool (www.turbotool.de) which features D&D input very well and was created with those applications in mind
</shameless plug>
I released an open-source freeware app that creates application bundles from scripts a while ago. It's called Platypus.
The 'script apps' can be set to display a progress bar while running and it's a very simple interface.
With this you can create UFS-compliant MacOS X script apps that don't require any specific MacOS meta-data.
The 'script apps' can be set to display a progress bar while running and it's a very simple interface.
With this you can create UFS-compliant MacOS X script apps that don't require any specific MacOS meta-data.
Wow. Talk about being on the same wavelength! We posted simiar messages within seconds of each other!
Spooky - I grabbed Platypus yesterday but haven't looked at it yet.
sveinbjorn thank you so much: your appl works, where the hint doesn't
Another way to create Finder-clickable shell scripts
Has anybody been successful with this hint? I get a -39 type error ('eofErr=-39, /*End of file*/') when I double click the .sh file modified with APPL Type code. The script is otherwise functional.
I tried to add a EOF line at the end of the file, but it makes no difference..
Can someone help?
I tried to add a EOF line at the end of the file, but it makes no difference..
Can someone help?
Another way to create Finder-clickable shell scripts
In Panther 10.3 shell scripts/unix executables become clickable
Another way to create Finder-clickable shell scripts
Under OSX 10.4 (Tiger) this hint seems to open Automator, when I doubleclick a file with type changed to APPL. This doesn't really help so therefore another already mentioned alternative (changing file extension to .command) seems to work better.
Another way to create Finder-clickable shell scripts
actually, it is better to change the Creator :
setFile -c trmx myScript
probably it is better to set the x flag (chmod +x myScript)
Now, does anyone know how to get the directory (in the script) where the file is located ?
setFile -c trmx myScript
probably it is better to set the x flag (chmod +x myScript)
Now, does anyone know how to get the directory (in the script) where the file is located ?