I have tried creating an application in Automator that when double clicked, will tar my To-Do.txt file. The command I'm using is pretty standard:
tar -cvzf ToDo.tar.gz /Users/myusername/Desktop/To-Do.txt
The above command works perfectly when entered into a terminal, so I created an application in Automator and put the 'Run Shell Script' action into the workflow with the command above. However, when I double click the application it does nothing at all.
If I run the workflow in automator, it runs successfully so I know there are no errors.
Can anyone tell me why this isn't working?
I have managed to get it to work by changing the 'Shell:' option to /bin/sh instead of /bin/bash.
Works really well. I also changed the specified filename to use arguments $# and can now Tar any file with it.
Related
First off I'm using Mac.
Next, I need to execute this "file.sh" we will call it. Everytime I need to execute it I have to open Terminal and type:
cd /Users/Jacob/Documents/folderWithFileInIt
bash file.sh
This is okay, but I feel like it would be a lot quicker if I make the file execute on double click, don't you think?
So my question is, how do I make this file executable via double click?
My ideas were either:
a) type something like chmod into terminal and change permissions?
b) make a file, put code I wrote above in it ^ and then make that file executable?
c) make an automation somehow to do this?
Which way is best, or is there an even better way?
By default, *.sh files are opened in a text editor (Xcode or TextEdit). To create a shell script that will execute in Terminal when you open it, name it with the “command” extension, e.g., file.command. By default, these are sent to Terminal, which will execute the file as a shell script.
You will also need to ensure the file is executable, e.g.:
chmod +x file.command
Without this, Terminal will refuse to execute it.
Note that the script does not have to begin with a #! prefix in this specific scenario, because Terminal specifically arranges to execute it with your default shell. (Of course, you can add a #! line if you want to customize which shell is used or if you want to ensure that you can execute it from the command line while using a different shell.)
Also note that Terminal executes the shell script without changing the working directory. You’ll need to begin your script with a cd command if you actually need it to run with a particular working directory. E.g. you can use cd "$(dirname "$0")" to set the current working directory to the directory where your shell script lies.
Remove the extension altogether and then double-click it. Most system shell scripts are like this. As long as it has a shebang it will work.
You can just tell Finder to open the .sh file in Terminal:
Select the file
Get Info (cmd-i) on it
In the "Open with" section, choose "Other…" in the popup menu
Choose Terminal as the application
This will have the exact same effect as renaming it to .command except… you don't have to rename it :)
Launch Terminal
Type -> nano fileName
Paste Batch file content and save it
Type -> chmod +x fileName
It will create exe file now you can double click and it.
File name should in under double quotes.
Since i am using Mac->In my case content of batch file is
cd /Users/yourName/Documents/SeleniumServer
java -jar selenium-server-standalone-3.3.1.jar -role hub
It will work for sure
you can change the file executable by using chmod like this
chmod 755 file.sh
and use this command for execute
./file.sh
nano ~/FILENAME
Write your bash script and exit nano with Ctrl + x and hit y
Make file an executable
chmod 700 ~/FILENAME
Bingo, the file turns an executable, double click to launch
Works without .sh extension or shebang (#!) prefix.
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'm on a Mac, and have a bash script that works very nicely.
I'd like to make it so that a double-click will run it, but I don't know the "open with" operand. Please, what am I missing?
You'll need to make the file an executable.
On the first line, before any of your code put in a shebang
#!/usr/bin/env bash
REST OF YOUR CODE HERE
Next, you'll need to change the permissions. On the terminal run:
chmod +x your_bash_file
Finally, you will need to make sure OS X opens the file using the Terminal and not the application that created the file e.g. your favourite text editor. You can accomplish this in 1 of two ways:
Save the file with no file extension (eg. bash_file, instead of bash_file.sh)
Or, choose File -> Get Info and set Open with: to Terminal.app
You should now be able to click on the script to execute it!
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
First off I'm using Mac.
Next, I need to execute this "file.sh" we will call it. Everytime I need to execute it I have to open Terminal and type:
cd /Users/Jacob/Documents/folderWithFileInIt
bash file.sh
This is okay, but I feel like it would be a lot quicker if I make the file execute on double click, don't you think?
So my question is, how do I make this file executable via double click?
My ideas were either:
a) type something like chmod into terminal and change permissions?
b) make a file, put code I wrote above in it ^ and then make that file executable?
c) make an automation somehow to do this?
Which way is best, or is there an even better way?
By default, *.sh files are opened in a text editor (Xcode or TextEdit). To create a shell script that will execute in Terminal when you open it, name it with the “command” extension, e.g., file.command. By default, these are sent to Terminal, which will execute the file as a shell script.
You will also need to ensure the file is executable, e.g.:
chmod +x file.command
Without this, Terminal will refuse to execute it.
Note that the script does not have to begin with a #! prefix in this specific scenario, because Terminal specifically arranges to execute it with your default shell. (Of course, you can add a #! line if you want to customize which shell is used or if you want to ensure that you can execute it from the command line while using a different shell.)
Also note that Terminal executes the shell script without changing the working directory. You’ll need to begin your script with a cd command if you actually need it to run with a particular working directory. E.g. you can use cd "$(dirname "$0")" to set the current working directory to the directory where your shell script lies.
Remove the extension altogether and then double-click it. Most system shell scripts are like this. As long as it has a shebang it will work.
You can just tell Finder to open the .sh file in Terminal:
Select the file
Get Info (cmd-i) on it
In the "Open with" section, choose "Other…" in the popup menu
Choose Terminal as the application
This will have the exact same effect as renaming it to .command except… you don't have to rename it :)
Launch Terminal
Type -> nano fileName
Paste Batch file content and save it
Type -> chmod +x fileName
It will create exe file now you can double click and it.
File name should in under double quotes.
Since i am using Mac->In my case content of batch file is
cd /Users/yourName/Documents/SeleniumServer
java -jar selenium-server-standalone-3.3.1.jar -role hub
It will work for sure
you can change the file executable by using chmod like this
chmod 755 file.sh
and use this command for execute
./file.sh
nano ~/FILENAME
Write your bash script and exit nano with Ctrl + x and hit y
Make file an executable
chmod 700 ~/FILENAME
Bingo, the file turns an executable, double click to launch
Works without .sh extension or shebang (#!) prefix.