I have a script written (which are basically the commands for the terminal for Ubuntu) on a file. Yes, the code starts with
#!/bin/bash
How do I run this script just by double clicking it? It can be run using the terminal but I want to make it more accessible through my desktop.
I was just trying to mimic a *.bat file on windows. A *.bat file on windows contains series of scripts operable on command prompt and executable just by double clicking on it.
Follow these steps:
Hit Alt+F2, type dconf-editor and hit ``Enter.
In dconfg-editor goto: org ➤ gnome ➤ nautilus ➤ preferences
Click on executable-text-activation and from drop down menu select:
launch: to launch scripts as programs.
OR
ask: to ask what to do via a dialog.
Close dconf-editor Thats it!
Source https://askubuntu.com/a/286651/113065
Edit -> preferences -> Behavior -> Executable Text Files = Run ...
It should run, but you can't see output.
An alternative way, mostly for developers, is to create self-contained desktop launchers. The idea is to use a launcher that includes a tag under which there is the script; the launcher executes a command that:
put the script into a temporary file
run the script which deletes itself
Of course, the script should delete itself, for this reason, it's a good practice to start the script with rm $0. Note that if the script needs to read the script itself, you will need to use rm $0 somewhere else...
You can use the following example stolen from my project:
#!/usr/bin/env xdg-open
[Desktop Entry]
Name=Launch Assistance
Comment=A simple app to setup remote assistance
Exec=ttt=/tmp/$(date +"%s%N").sh; tail -n+$(awk '/^#__SCRIPT__#/ {print NR + 1; exit 0; }' %k) %k > $ttt ; sh $ttt;
Icon=computer
Terminal=true
Type=Application
Categories=Network;Internet;Utilities;Administration;Settings;
#__SCRIPT__#
rm "$0"
# Put here the script
# note that if the script needs to read $0, you will have to edit it
You need to make it an executable file, either use chmod +x <filename> or go into the file properties and set it there.
Open nautilus
Behavior tab
Executable Text files -> Ask each time
Profit
Source. Tested on Ubuntu 20.04.
I have a script that I'd like to run.
I know I can open a terminal and run the command:
open -na /Applications/Skype2.app \
--args -DataPath /Users/$(whoami)/Library/Application\ Support/Skype2
But how can I run it by double clicking on the script, similar to an app or exe file in windows?
An easy way is use the Automator app to create an "Application" containing a Run Shell Script action.
If thats too GUI for you, see https://stackoverflow.com/a/5126052/153099
I am trying to start a dxl script with command line. But i am getting lots of warnings and errors.
When I try this script on doors gui , it works fine but when i try on this command line without gui, it doesn't.
Here is the image of warnings :
Here is the commandline script :
"%ProgramFiles%\IBM\Rational\DOORS\9.3\bin\doors.exe" -d 36677#bie -u "xxx yyy" -P don -b "d:\workset\mc\addins\Devel\exporterRTF.dxl"
Why it doesn't work with commandline ? Any help, idea etc is appreciated.
EDIT :
this is a link which i try to run : myprogram.dxl
this is a link which is imported in my running script include in myprogram.dxl
this is a link which is secondly imported in my running script include in myprogram.dxl
There are other settings you need to run in Batch mode (pulled from the DOORS help):
Runs Rational DOORS in batch mode. Rational DOORS starts without the GUI (it suppresses the login screen and the database explorer), runs the specified DXL program, and then stops.
In batch mode you normally need other switches like -user, -password and -project to log in and specify the current project.
The parameter of the -batch switch specifies the file that contains the DXL program that you want to run in batch mode.
You probably need a current project specified. Also you may need to add a command at the end of your script to exit DOORS if you don't want the session to stay open.
The errors that you list seem like regular DXL errors, so if you need more assistance than this, you will need to post some of the code.
EDIT:
If you put all of the files into one does it run? Another option may be to include the Addins path on your command line. I believe the issue is that the batch mode is not recognizing the included files as part of the same scope.
I'd like to be able to run a script in the background (i.e. without blocking the build process) when I build and run an iOS application in the simulator. I've tried osascript /path/to/script &, and also backgrounding a separate shell script that does the same, but neither have worked; the build stops and I have to force quit XCode.
Any ideas?
I had the same trouble with running a background script as part of the build phase but the following does work in my case. The script runs in the background while my app runs. Apparently, you have to redirect the standard output in addition to using the "&". Use the following format. (My script is located in directory '~/Desktop/splint_server/')
~/Desktop/splint_server/run.sh > ~/Desktop/splint_server/test 2>&1 &
This runs an arbitrary script at ~/Desktop/splint_server/run.sh (put the path to your script there). The output is redirected to a log file called "test".
More information about I/O redirection http://www.tldp.org/LDP/abs/html/io-redirection.html
Incase you are still interested.
These are the steps you need to follow:
1. Change the .sh extension of your script to .command
2. Rather than invoking /path/to/script.sh you now start using "open /path/to/script.command"
Thats pretty much it.
This will start a new terminal window and run the script you want in it.
You could use post-actions of build in the schemes setting.
"sleep 100&" works fine
How do I set up a shell script to execute from the Mac OSX dock? It seems that simply creating a shortcut will open the file in my editor. Is there a flag I need to set somewhere to tell it to run instead of opening it for editing?
You could create a Automator workflow with a single step - "Run Shell Script"
Then File > Save As, and change the File Format to "Application". When you open the application, it will run the Shell Script step, executing the command, exiting after it completes.
The benefit to this is it's really simple to do, and you can very easily get user input (say, selecting a bunch of files), then pass it to the input of the shell script (either to stdin, or as arguments).
(Automator is in your /Applications folder!)
If you don't need a Terminal window, you can make any executable file an Application just by creating a shell script Example and moving it to the filename Example.app/Contents/MacOS/Example. You can place this new application in your dock like any other, and execute it with a click.
NOTE: the name of the app must exactly match the script name. So the top level directory has to be Example.app and the script in the Contents/MacOS subdirectory must be named Example, and the script must be executable.
If you do need to have the terminal window displayed, I don't have a simple solution. You could probably do something with Applescript, but that's not very clean.
On OSX Mavericks:
Create your shell script.
Make your shell script executable:
chmod +x your-shell-script.sh
Rename your script to have a .app suffix:
mv your-shell-script.sh your-shell-script.app
Drag the script to the OSX dock.
Rename your script back to a .sh suffix:
mv your-shell-script.app your-shell-script.sh
Right-click the file in Finder, and click the "Get Info" option.
At the bottom of the window, set the shell script to open with the terminal.
Now when you click on the script in the dock, A terminal window will pop up and execute your script.
Bonus: To get the terminal to close when your script has completed, add exit 0 to the end and change the terminal settings to "close the shell if exited cleanly" like it says to do in this SO answer.
I know this is old but in case it is helpful to others:
If you need to run a script and want the terminal to pop up so you can see the results you can do like Abyss Knight said and change the extension to .command. If you double click on it it will open a terminal window and run.
I however needed this to run from automator or appleScript. So to get this to open a new terminal the command I ran from "run shell script" was "open myShellScript.command" and it opened in a new terminal.
As long as your script is executable and doesn't have any extension you can drag it as-is to the right side (Document side) of the Dock and it will run in a terminal window when clicked instead of opening an editor.
If you want to have an extension (like foo.sh), you can go to the file info window in Finder and change the default application for that particular script from whatever it is (TextEdit, TextMate, whatever default is set on your computer for .sh files) to Terminal. It will then just execute instead of opening in a text editor. Again, you will have to drag it to the right side of the Dock.
In the Script Editor:
do shell script "/full/path/to/your/script -with 'all desired args'"
Save as an application bundle.
As long as all you want to do is get the effect of the script, this will work fine. You won't see STDOUT or STDERR.
I think this thread may be helpful: http://forums.macosxhints.com/archive/index.php/t-70973.html
To paraphrase, you can rename it with the .command extension or create an AppleScript to run the shell.
As joe mentioned, creating the shell script and then creating an applescript script to call the shell script, will accomplish this, and is quite handy.
Shell Script
Create your shell script in your favorite text editor, for example:
mono "/Volumes/Media/~Users/me/Software/keepass/keepass.exe"
(this runs the w32 executable, using the mono framework)
Save shell script, for my example "StartKeepass.sh"
Apple Script
Open AppleScript Editor, and call the shell script
do shell script "sh /Volumes/Media/~Users/me/Software/StartKeepass.sh" user name "<enter username here>" password "<Enter password here>" with administrator privileges
do shell script - applescript command to call external shell commands
"sh ...." - this is your shell script (full path) created in step one (you can also run direct commands, I could omit the shell script and just run my mono command here)
user name - declares to applescript you want to run the command as a specific user
"<enter username here> - replace with your username (keeping quotes) ex "josh"
password - declares to applescript your password
"<enter password here>" - replace with your password (keeping quotes) ex "mypass"
with administrative privileges - declares you want to run as an admin
Create Your .APP
save your applescript as filename.scpt, in my case RunKeepass.scpt
save as... your applescript and change the file format to application, resulting in RunKeepass.app in my case
Copy your app file to your apps folder
Exact steps to achieve that in macOS Monterey 12.3
Open Automator
File -> New
Choose Application
Go to Library -> Utilities
Double-click Run Shell Script
Type in whatever command you want to run. For example, try the command to toggle Dark Mode:
osascript -e 'tell app "System Events" to tell appearance preferences to set dark mode to not dark mode'
File -> Save
Drag the saved file to the Dock, done!
pip install mac-appify
I had trouble with the accepted solution but this command worked for me.
Install
pip install mac-appify
Run
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/appify ~/bin/webex_start.sh ~/Desktop/webex.app
Adding to Cahan's clear answer ... to open a shell script from the dock without passing any arguments to it, try:
open [name of your script].scpt"
example:
open "//Users/user/Library/Mobile Documents/com~apple~ScriptEditor2/Documents/myScript.scpt"
Someone wrote...
I just set all files that end in ".sh" to open with Terminal. It works
fine and you don't have to change the name of each shell script you
want to run.