Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Can this script be combined into 1 command?

Can this script be combined into 1 command?
Thread Tools
Mac Enthusiast
Join Date: Apr 2001
Status: Offline
Reply With Quote
Sep 9, 2003, 11:31 PM
 
Ok this script I just wrote a few minutes ago is a quick hack for OnMyCommandCM
which is an awesome add on for OS X. The script makes a dir named like this example

Gathered Items (Tue, Jul 29, 2003 12.11.26 PM)

and moves everything you have selected in the finder into that dir. Works great but
to get it to run in silent mode I need to if possible combine all that into one command

I have had no luck getting the syntax just right so here I am asking for UNIX shell guru help

is it possible? if so please post your solution

thx


Code:
set thedate=`date '+Gathered Items (%a, %b %d, %Y'` set thehour=`date '+%H'` set theminutesecond=`date '+%M.%S'` if ($thehour >= 12) then set ampm="PM" if ($thehour > 12) then set thehour = `expr $thehour - 12` endif else set ampm="AM" if ($thehour == 00) then set thehour = 12 endif endif mkdir __OBJ_COMMON_PARENT_PATH__"$thedate $thehour.$theminutesecond $ampm)" mv __OBJ_PATH__ __OBJ_COMMON_PARENT_PATH__"$thedate $thehour.$theminutesecond $ampm)"/
     
Mac Elite
Join Date: Oct 2000
Location: Seattle
Status: Offline
Reply With Quote
Sep 10, 2003, 05:28 AM
 
I'm not a UNIX shell guru but I play one on TV.

You can replace all the date stuff with one line:

set thedate = `date '+Gathered Items (%a, %b %d, %Y %I:%M:%S %p)'`

I think %I and %p will do what you want. See man strftime

To place several commands on one line separate them with semicolons.

So, try playing around with this:

set new_dir = `date '+Gathered Items (%a, %b %d, %Y %I:%M:%S %p)'`; mkdir __OBJ_COMMON_PARENT_PATH__"$new_dir"; mv __OBJ_PATH__ __OBJ_COMMON_PARENT_PATH__"$new_dir"
You can take the dude out of So Cal, but you can't take the dude outta the dude, dude!
     
Groovy  (op)
Mac Enthusiast
Join Date: Apr 2001
Status: Offline
Reply With Quote
Sep 10, 2003, 01:59 PM
 
Originally posted by Gavin:
I'm not a UNIX shell guru but I play one on TV.

You can replace all the date stuff with one line:

set thedate = `date '+Gathered Items (%a, %b %d, %Y %I:%M:%S %p)'`

I think %I and %p will do what you want. See man strftime

if only man date SHOWED the %I and %p options grr...... hahaha

the main reason I split it up was I needed to if then $thehour and I could not if all the date and time were
in one var. I could NOT find all the formats options so I was forced to split it up but strftime shows them all.
YEAH! so I can dump the splitting and if then stuff. cool



Originally posted by Gavin:

To place several commands on one line separate them with semicolons.

So, try playing around with this:

set new_dir = `date '+Gathered Items (%a, %b %d, %Y %I:%M:%S %p)'`; mkdir __OBJ_COMMON_PARENT_PATH__"$new_dir"; mv __OBJ_PATH__ __OBJ_COMMON_PARENT_PATH__"$new_dir"


LOL with the better formating for date and no need for if then etc.... very easy to get on one line.
You think it is possible if you had to in case in the future one needed to get all that on one line?

I mean I got lucky here because %I and %p solved the problem but there may come a time when
a script snippet might have to be combined



Anway thanks, this fixes everything
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:25 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2