I have a fairly good amount of knowledge with Batch. I'm trying to port a batch script over to Mac/UNIX, but my batch file has a drag-and-drop thing to it. Through countless Google searches, I have came up with nothing. They all say that you can drag-and-drop into a Terminal Window - not good for no-input-required scripts.
Here is the code for Batch I have:
cd %USERPROFILE%
7za x %* -o%USERPROFILE%\Desktop\Temp
7za a %1 %USERPROFILE%\Desktop\Temp\*
cd %USERPROFILE%\Desktop
rmdir /q /s Temp\
Not particularly worried about 7za commands (because of Archive Utility),cd %USERPROFILE%
(because Terminal starts in the user's profile), rmdir
, cd
, and such, as they are only basic file commands. But I don't know the code to reference to the file dropped/opened with the .sh script.
So, if someone knows that code, please tell me. I know this is kind-of a simple thing, but you can't know every command, especially when dealing with unfamiliar programming languages.
A shell script or sh-file is something between a single command and a (not necessarily) small programm. The basic idea is to chain a few shell commands together in a file for ease of use. So whenever you tell the shell to execute that file, it will execute all the specified commands in order.
Open Command Prompt and navigate to the folder where the script file is available. Type Bash script-filename.sh and hit the enter key.
I don't know of a way to have the raw script accept drag-and-dropped files, but there are a number of options to wrap it in something else that accepts drag-and-drop, and passes the files to a script. IMO the quickest option is to wrap the script in an Automator application. Run /Applications/Automator.app, select Application as the type for your new project, drag the "Run Shell Script" action from the actions list (second column) into the workflow (right column), set its "Pass input" to "as arguments", paste in the shell script, then save the app. Done.
Other options for wrapping a shell script include: AppleScript, Platypus, and DropScript.
I'm late to this, and don't even have the answer to your drag-and-drop question. But I notice this looks like a Batch script for Windows' cmd.exe
which will not work at all in any Unix shell. So you really need to completely rewrite it for Bash first!
%USERPROFILE%
variable would be $HOME
in Unix.rmdir
only deletes empty directories. See man rmdir
and man rm
with the -f -r
options for an equivalent of your rmdir /q /s Temp
Windows command.But beware that once you learn some Bash, you will start to really hate that horrible cmd.exe
:-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With