Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

connred

macrumors newbie
Original poster
Feb 11, 2015
1
0
Hi,
I do not know much and Im just getting into things. I am trying to create a .sh that can take a file, copy it, and then replace it with an existing file. I know how to do it in terminal, but I would to do it with a click of a button.
Anyhelp? I know i'm not very experienced..
Thanks
 
I would to do it with a click of a button.

Shell Scripts (.sh files) are normally entered on the command line to run them, not clicked with a button.

When you're talking about something that only people familiar with the command line are using which doesn't benefit from a visual component, I'd say it's better to just leave it that way, too.

Final thought: I'd recommend Python instead of Shell. Shell scripts only work on *nix systems whereas Python scripts will run anywhere, including but not limited to *nix and Windows.
 
I'd echo what ArtOfWarfare says, although I'd add that you can also call a shell script from an AppleScript which *can* run from a mouse click if you save it as an application. As an example,

Code:
set theDate to do shell script "date"

However, if you're going to use AppleScript anyway then there's not really much point stepping out into "do shell script", you can move and delete files easy enough with pure AppleScript.
 
Lots of stuff online about writing shell scripts. In summary create a file

On the first line indicate what shell you want to use - something like

Code:
#!/bin/sh

follow that with the command(s) that you've been putting into terminal

save the file and make it executable by the command

Code:
chmod +x filename

That works if you want to issue the same command over and over again.
If you want to use parameters, then you can refer to them in your script as $1, $2 etc. But, after that you're really getting into the realm of parameter checking, raising errors. All good stuff, but may be overkill for what you need
 
...or just change the file extension from .sh to .command

OS X will let you run it by double-clicking.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.