system admin script

Discussion in 'Ruby' started by Ott Mr, Jul 20, 2008.

  1. Ott Mr

    Ott Mr Guest

    i am trying to find a good scripting language for Mac OS X. I was told
    ruby would be a good choice. Before i dedicate my time to learning it I
    have to find out a couple of things.


    Can you run ruby form the GUI? i.e double click it . I don't want users
    to have to go to the terminal.

    Here is an example of what i would like to do. We use a package builder
    to customize installs. The only part that it can't do is user related
    preferences and library files. Which means we(IT department) have to
    copy the files. It is easy to do and it only takes about 3mins. But it
    would be nice if i could just double click a script and have it take
    5sec. Is this something I can do with ruby?

    I am more concerned with running it from a GUI. If I can't do that I
    might as well stick to shell scripts because I can call them from apple
    script which I can run form the GUI. Plus I already know shell
    scripting.
    --
    Posted via http://www.ruby-forum.com/.
    Ott Mr, Jul 20, 2008
    #1
    1. Advertising

  2. Ott Mr

    John Joyce Guest

    On Jul 19, 2008, at 9:10 PM, Ott Mr wrote:

    > i am trying to find a good scripting language for Mac OS X. I was told
    > ruby would be a good choice. Before i dedicate my time to learning
    > it I
    > have to find out a couple of things.
    >
    >
    > Can you run ruby form the GUI? i.e double click it . I don't want
    > users
    > to have to go to the terminal.
    >
    > Here is an example of what i would like to do. We use a package
    > builder
    > to customize installs. The only part that it can't do is user related
    > preferences and library files. Which means we(IT department) have to
    > copy the files. It is easy to do and it only takes about 3mins. But it
    > would be nice if i could just double click a script and have it take
    > 5sec. Is this something I can do with ruby?
    >
    > I am more concerned with running it from a GUI. If I can't do that I
    > might as well stick to shell scripts because I can call them from
    > apple
    > script which I can run form the GUI. Plus I already know shell
    > scripting.
    > --
    > Posted via http://www.ruby-forum.com/.
    >


    You can make anything executable. But if you want it double clickable,
    you might want to wrap it in a simple apple script or use Ruby Cocoa.
    You're making a double-clickable tool, so you should give the users
    some feedback.

    You might even just consider a cron job or use net booting for os x,
    or even ARD.

    You can wrap any script in AppleScript just like you already know how
    to do with shell scripts.
    Ruby works just as well, but is much less terse than sh scripting.
    Just remember the usual caveats about permissions and such.
    For distribution, ctrl click and select 'archive", which will create a
    zip, or put it in a disk image (dmg) and that will prevent permissions
    issues.

    Sounds like you may want to just use sh and applescript, since you
    already know it, but you can literally use Ruby the same way.
    You could (painfully at times) do the whole thing in applescript, but
    that would probably be slow as dirt too.

    Almost as easily and much nicer, you can do the same thing from a
    simple Cocoa app in Xcode and add a simple GUI to it.

    There is also Platypus for wrapping scripts in simply GUI
    John Joyce, Jul 20, 2008
    #2
    1. Advertising

  3. Ott Mr

    John Joyce Guest

    On Jul 20, 2008, at 9:32 AM, John Joyce wrote:

    >
    > On Jul 19, 2008, at 9:10 PM, Ott Mr wrote:
    >
    >> i am trying to find a good scripting language for Mac OS X. I was
    >> told
    >> ruby would be a good choice. Before i dedicate my time to learning
    >> it I
    >> have to find out a couple of things.
    >>
    >>
    >> Can you run ruby form the GUI? i.e double click it . I don't want
    >> users
    >> to have to go to the terminal.
    >>
    >> Here is an example of what i would like to do. We use a package
    >> builder
    >> to customize installs. The only part that it can't do is user related
    >> preferences and library files. Which means we(IT department) have to
    >> copy the files. It is easy to do and it only takes about 3mins. But
    >> it
    >> would be nice if i could just double click a script and have it take
    >> 5sec. Is this something I can do with ruby?
    >>
    >> I am more concerned with running it from a GUI. If I can't do that I
    >> might as well stick to shell scripts because I can call them from
    >> apple
    >> script which I can run form the GUI. Plus I already know shell
    >> scripting.
    >> --
    >> Posted via http://www.ruby-forum.com/.
    >>


    Leopard's Automator has a nice tool as well...
    in Automator, choose Actions > Utilities > Run Shell Script
    and your work flow is almost done.
    The "Run Shell Script" workflow includes Ruby in its list. (as well as
    each shell and python and perl)
    John Joyce, Jul 20, 2008
    #3
  4. Ott Mr

    Phlip Guest

    Ott Mr wrote:

    > Here is an example of what i would like to do. We use a package builder
    > to customize installs. The only part that it can't do is user related
    > preferences and library files. Which means we(IT department) have to
    > copy the files. It is easy to do and it only takes about 3mins. But it
    > would be nice if i could just double click a script and have it take
    > 5sec. Is this something I can do with ruby?


    In general, in addition to the other answers, I would try this:

    - install Ruby on Rails
    - write one page
    - put one button on it
    - install an Authentication plugin
    - give your users accounts
    - when they click the button, paint a page showing what they did
    - deploy your RoR site to an intranet server

    We do that at work. Rails is the front-end to our corporate database. Each
    feature the knowledge workers need, they request it, and we add it to the Rails
    project. The turnaround on this system can be as short as a couple hours for a
    new button, or a week for a whole new page.

    Classical web systems, such as ASP.NET or Tomcat, are way too top-heavy for you
    to consider using them for your in-house administration interface. Don't think
    Rails will be like that!

    --
    Phlip
    Phlip, Jul 20, 2008
    #4
  5. On Jul 19, 2008, at 7:10 PM, Ott Mr wrote:

    > i am trying to find a good scripting language for Mac OS X. I was told
    > ruby would be a good choice. Before i dedicate my time to learning
    > it I
    > have to find out a couple of things.
    >
    >
    > Can you run ruby form the GUI? i.e double click it . I don't want
    > users
    > to have to go to the terminal.


    Yes! It doesn't even have to be limited to OS X either. I'd look into
    JRuby's Monkeybars library (which includes screencasts): http://monkeybars.rubyforge.org/

    You can use a visual designer such as Netbeans to drag and drop
    buttons onto the form.
    Monkeybars uses JRuby (Ruby for Java), and since Java is installed on
    all Macs, you can just push around your app without having to install
    any dependencies or making sure you have the right version of the
    particular scripting language you want to use. JRuby is just a Java
    library, and you can simply package JRuby along with your app.

    >
    > Here is an example of what i would like to do. We use a package
    > builder
    > to customize installs. The only part that it can't do is user related
    > preferences and library files. Which means we(IT department) have to
    > copy the files. It is easy to do and it only takes about 3mins. But it
    > would be nice if i could just double click a script and have it take
    > 5sec. Is this something I can do with ruby?


    Yes. With Rawr you simply enter 'rake rawr:bundle:app' at the command
    line and Rawr will bundle up your application into a standard Mac .app
    file. I have three Monkeybars apps bundled this way that are sitting
    on my dock right now.

    >
    >
    > I am more concerned with running it from a GUI. If I can't do that I
    > might as well stick to shell scripts because I can call them from
    > apple
    > script which I can run form the GUI. Plus I already know shell
    > scripting.


    Ruby has methods of making complicated console calls such as system,
    sh, and the backtick (`). For example:
    system "cd foo"
    system "rm bar"

    sh works in a similar way (I believe there is a difference in console
    control, and what spawns off as a new process vs. a blocking process.
    Don't quote me on that).

    sh "cd foo"
    sh "rm bar"

    Ruby also has a backtick, a literal that's just for sending commands:
    `cd foo`
    `rm bar`

    Ruby also has a bunch of file operations inside of File and FileUtils.
    There's even an Etc object for doing some common operations for things
    you normally see in the /etc directory.

    Myself and a few others are typically hanging out in the #jruby and
    #monkeybars channel on freenode, and we're always willing to give a
    hand with these tools. Monkeybars, Rawr, and JRuby all have mailing
    lists if you'd prefer to contact us that way as well.
    Logan Barnett, Jul 20, 2008
    #5
  6. Ott Mr

    Phlip Guest

    > Ruby has methods of making complicated console calls such as system,
    > sh, and the backtick (`).


    Yes!

    > For example:


    > system "cd foo"
    > system "rm bar"


    No!

    Firstly, the cd can't influence the rm, because they ran in different contexts.

    Nextly, only use system when you can't use a raw Ruby call. They are much more
    typesafe:

    Dir.chdir 'foo' do
    Pathname.new('bar').unlink
    end

    --
    Phlip
    Phlip, Jul 20, 2008
    #6
  7. Ott Mr wrote:
    > i am trying to find a good scripting language for Mac OS X. I was told
    > ruby would be a good choice. Before i dedicate my time to learning it I
    > have to find out a couple of things.
    >
    >
    > Can you run ruby frorm the GUI? i.e double click it . I don't want users
    > to have to go to the terminal.


    You can use "Platypus" to wrap ruby and shell scripts in a nice
    double clickable wrapper. http://www.sveinbjorn.org/platypus

    Keep in mind that if you require a user interface with buttons
    and menus, you will need to script all that in ruby using one
    of the gui add-ons. Or, if you only require a limited user
    interaction, similar to what one could do in applescript, then
    you could use rb-appscript to access the
    Applescript scripting additions which provide for such interactions.

    >
    > Here is an example of what i would like to do. We use a package builder
    > to customize installs. The only part that it can't do is user related
    > preferences and library files. Which means we(IT department) have to
    > copy the files. It is easy to do and it only takes about 3mins. But it
    > would be nice if i could just double click a script and have it take
    > 5sec. Is this something I can do with ruby?


    Yes, you could do this with ruby, but also with plain Applescript.
    Or a shell script with Platypus wrapper....
    I'm not sure ruby provides a big advantage here...

    vince
    --
    Posted via http://www.ruby-forum.com/.
    Vince Angeloni, Jul 21, 2008
    #7
  8. Ott Mr

    Kaldrenon Guest

    On Jul 19, 10:10 pm, Ott Mr <> wrote:
    > i am trying to find a good scripting language for Mac OS X. I was told
    > ruby would be a good choice. Before i dedicate my time to learning it I
    > have to find out a couple of things.
    >
    > Can you run ruby form the GUI? i.e double click it . I don't want users
    > to have to go to the terminal.
    >
    > Here is an example of what i would like to do. We use a package builder
    > to customize installs. The only part that it can't do is user related
    > preferences and library files. Which means we(IT department) have to
    > copy the files. It is easy to do and it only takes about 3mins. But it
    > would be nice if i could just double click a script and have it take
    > 5sec. Is this something I can do with ruby?
    >
    > I am more concerned with running it from a GUI. If I can't do that I
    > might as well stick to shell scripts because I can call them from apple
    > script which I can run form the GUI. Plus I already know shell
    > scripting.


    I'm not a MacOS user, so I don't know much about this, but does MacOS
    X have something equivalent to Windows' batch files? In Windows, you
    could make any ruby program double-click executable by making a file
    called [program_name.bat] and giving it the line "ruby path
    \program_name.rb"
    Kaldrenon, Jul 21, 2008
    #8
  9. Ott Mr

    Une Bévue Guest

    Ott Mr <> wrote:

    > Can you run ruby form the GUI? i.e double click it . I don't want users
    > to have to go to the terminal.


    the simplest way is to put an extension od command to your script, it
    will be executed on the teminal automagically.

    for example :

    --- code --------------------------
    #!/usr/bin/env ruby
    `say hello`
    --- /code --------------------------

    save it as "say_hello.command" ( may be with x perms, don't remember

    and it will open a term and say "hello"...
    --
    Une Bévue
    Une Bévue, Jul 21, 2008
    #9
  10. On Sunday 20 July 2008 11:04:45 Phlip wrote:

    > Dir.chdir 'foo' do
    > Pathname.new('bar').unlink
    > end


    And this is an example of when a shell script may be more appropriate.

    Ruby is great as soon as you need just about any structure at all, but I
    wouldn't use it for what would be a one-liner in the shell, except to call
    that one-liner in the shell:

    system 'cd foo; rm bar'

    Or even:

    rm 'foo/bar'

    It would help if we knew more about what's needed by that script.
    David Masover, Jul 23, 2008
    #10
  11. Kaldrenon wrote:
    > I'm not a MacOS user, so I don't know much about this, but does MacOS
    > X have something equivalent to Windows' batch files? In Windows, you
    > could make any ruby program double-click executable by making a file
    > called [program_name.bat] and giving it the line "ruby path
    > \program_name.rb"
    >


    This is probably one of the few times I've seen someone say "does XYZ
    have an equivalent to this Windows ability?" :)

    Since I'm still on Windows quite often (due to reasons I don't wish to
    detail), it's nice to see :)

    Cheers,
    Mohit.
    12/31/2008 | 12:00 AM.
    Mohit Sindhwani, Dec 30, 2008
    #11
  12. very simply,
    you need to make your script shell executable.

    1 - Put a shebang line as the first line of your script: #!/usr/bin/env rub=
    y
    2 - make your script executable, with something like 'chmod a+x
    /your_file.rb' in the shell
    3 - then to make it clickable, change its extension from .rb to .command.

    voil=E0!

    2008/12/30 Mohit Sindhwani <>

    > Kaldrenon wrote:
    >
    >> I'm not a MacOS user, so I don't know much about this, but does MacOS
    >> X have something equivalent to Windows' batch files? In Windows, you
    >> could make any ruby program double-click executable by making a file
    >> called [program_name.bat] and giving it the line "ruby path
    >> \program_name.rb"
    >>
    >>

    >
    > This is probably one of the few times I've seen someone say "does XYZ hav=

    e
    > an equivalent to this Windows ability?" :)
    >
    > Since I'm still on Windows quite often (due to reasons I don't wish to
    > detail), it's nice to see :)
    >
    > Cheers,
    > Mohit.
    > 12/31/2008 | 12:00 AM.
    >
    >
    >
    Louis-Philippe, Dec 30, 2008
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Bevilaqua
    Replies:
    0
    Views:
    702
    John Bevilaqua
    Aug 19, 2003
  2. Replies:
    0
    Views:
    272
  3. vincent
    Replies:
    0
    Views:
    304
    vincent
    Aug 21, 2006
  4. sarah Fernandes
    Replies:
    0
    Views:
    485
    sarah Fernandes
    Nov 1, 2010
  5. Phlip
    Replies:
    1
    Views:
    270
    Eero Saynatkari
    Sep 15, 2006
Loading...

Share This Page