APLawrence - Information and Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds Get APLawrence.com by RSS













Best of the Newsgroups: script files on Mac OS X


What is this stuff?

Main Index

From: Bob Harris <nospam.News.Bob@remove.Smith-Harris.us>
Subject: Re: wget -- input file delimiters?
References: <0001HW.BEDAEF200031CD2FF02845B0@news.readfreenews.net> <190620051347235059%doozy@earthling.net.invalid> <tomstiller-2B54F4.14074619062005@comcast.dca.giganews.com> <0001HW.BEDB22ED0000A058F04885B0@news.readfreenews.net> 
Message-ID: <nospam.News.Bob-AEDD7D.19284219062005@news.verizon.net> 
Date: Sun, 19 Jun 2005 23:28:17 GMT

In article <0001HW.BEDB22ED0000A058F04885B0@news.readfreenews.net>,
 DaveC <me@privacy.net> wrote:

> Thus spake Tom Stiller: 
> 
> > In article <190620051347235059%doozy@earthling.net.invalid>,
> >  Philo D <doozy@earthling.net.invalid> wrote:
> 
> >> CR = control-M
> >> LF = control-J
> 
> > Get the free application TextWrangler from Bare Bones Software.  It 
> > allows one to specify the line ending to be used.
> 
> Thanks, guys.
> 
> Also, I'd like to know how to specify the wget command and all its parameters 
> in a file and execute it from Terminal. 
> 
> Possible? If so, how (preferably w/o scripts)?
> 
> Thanks,


cartoon
ad

use and editor such as TextWrangler 
<http://www.versiontracker.com/dyn/moreinfo/macosx/18529>
Then enter the #! line shown below followed by any number of commands 
line want to be executed in sequence:

        #!/usr/bin/sh   # have this bit of magic as the very 1st line
        wget ...

Then use "Save as..." -> Options -> Line Breaks -> UNIX
to get a file with <LF> as your line terminators.

Or you can use an editor such as pico (/usr/bin/pico) to edit your file  
from the terminal:

        pico your_wget_file
        
        #!/usr/bin/sh   # have this bit of magic as the very 1st line
        wget ...

        Control/O       # to write your file out
        Control/X       # to exit pico


cartoon
Take Control of Your iPhone Apps


One final thing, execute the following command:

        chmod +x your_wget_file

This will make your command executable. 

But wait there's more.  Isn't this fun?  :-)

Ideally, you want this file to be stored in a directory that is part of 
your "PATH".  Where PATH is a UNIX environment variable that contains as 
list of directories the shell (giving your your command line prompt in 
the Terminal window) will search looking for executable files that match 
the name of the command you type.

        echo $PATH

will give you a colon separated list of directory paths.  I personally 
create a $HOME/bin directory where I stick my personal commands

        mkdir $HOME/bin
        mv your_wget_file $HOME/bin

You could create this from the Finder, and drag and drop your_wget_file 
into $HOME/bin via the Finder.

Then I edit my .bash_profile file (if running the bash shell), or .login 
if running the tcsh or csh shells, or the .profile if running ksh or sh 
shells, and in the .bash_profile, or .login, or .profile, I put:

        export PATH="$HOME/bin:$PATH"   # sh, ksh, bash, zsh
or
        setenv PATH "$HOME/bin:$PATH"   # csh, tcsh

I also explicitly set the access permissions to:

        chmod 644 $HOME/.bash_profile
or
        chmod 644 $HOME/.login
or
        chmod 644 $HOME/.profile

Some people set the permissions even more strict, but I do not care if 
anyone reads my script initializations, just so no one can change them.

Another approach is to give the file a .command suffix as in

        your_wget_file.command

and make the file executable

        chmod +x your_wget_file.command

then you can double click on it from the Finder.  However, I don't 
really like this as it always seems to open up a new terminal window and 
then leave the window hanging around.  Not my cup of tea.

You can so do things like create an AppleScript to launch your shell 
commands in a file (I know I'm skating dangerously close to calling the 
shell commands in a file a script :-)

on open filelist
  repeat with i in filelist
    -- next line that looks like 2 is all one long line
    do shell script "$HOME/bin/your_wget_file >/dev/null " & quoted form 
of POSIX path of i
  end repeat
end open

If there are no drag and drop files to be processed, then you can omit 
the & quoted... stuff

on open filelist
  repeat with i in filelist
    do shell script "$HOME/bin/your_wget_file >/dev/null"
  end repeat
end open

The >/dev/null makes sure that anything spit to standard output by 
your_wget_file will be thrown away.  Take it out if you want to see what 
gets spit out.

You would use create this tiny little Applescript using 
Applications -> Applescript -> Script Editor
and "Save as..." Application or Application Bundle.
Now you would have double clickable (or drag and drop'able) program like 
thing that would run your wget command(s)

                                        Bob Harris
Comments /Bofcusm/2552.html


Add your comments