New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

scripted "if" shutdown


Post Reply New Thread Subscribe

 
Thread Tools
skary

 
Member Since: May 17, 2010
Posts: 3
skary is on a distinguished road

skary is offline
I was told this forum would be appropriate to post a question about applescript. Using automator, I have created a "timeInAndOut.app". Currently it is set as a login item, so every time i log into my work computer, it opens textedit, opens a specific file on my desktop, copies the date and time to clipboard and then pastes it into the text file and closes textedit, saving the file.

Originally i thought about just running the .app as a logouthook, but idk if that is going to work like i want it, or at all. I have decided the easiest way would be a simple script that checks the time and if it is between a certain time, the cpu should shutdown.

normally i just use control-option-command-eject to shutdown at the end of my split shift, but it would be nice to just run that script, have it log the date and time and shutdown the computer.

it should be a simple "if" condition, but idk how to properly word the syntax. Any help would be greatly appreciated.
QUOTE Thanks
scathe

 
scathe's Avatar
 
Member Since: Jan 12, 2009
Location: Prague, Czech Republic
Posts: 1,096
scathe is a jewel in the roughscathe is a jewel in the rough
Mac Specs: 2,4Ghz 15" unibody

scathe is offline
So much work when you can just run a simple bash script to log the time:
date >> myFile.txt
(>> appends to the file, instead of overwriting)

or in applescript:
do shell script "date >> myFile.txt"

Much more effective then opening text editing and copy/pasting there will be ways to do this inside of applescipt as well, I just don't know how exactly. I don't want to force this on you, it's just a suggestion.


As for the rest of your post I'm confused as to why would you run a script to check the time? you want to run this manually? For shutdown I would just create an applescript/app that could be called myShutdown which would log in the same manner and then shutdown, but you want to have this running all the time? you mean like a process in the background waiting for a certain time to shutdowm?

Edit:
Oh, I think I get it now, you want to have a background process periodically checking the time and shutting down your computer at a certain time? Why not use the system Scheduler found in System Preferences under Energy Saver?
QUOTE Thanks
skary

 
Member Since: May 17, 2010
Posts: 3
skary is on a distinguished road

skary is offline
no i don't want it running all the time eating up clock cycles. it's really just for my own education and amusement. i simply want a record of all the times my account is logged into and out of. just for record keeping purposes, so i can compare my actual time sheet to the dates and times listed here.

I like the bash script idea, and i'm not opposed to it, i just have most of the work done already and thought a couple IF statements might no be so difficult. everything i have script-wise i just copied and pasted from other scripts. I can read the scripting, just not write it.
QUOTE Thanks
scathe

 
scathe's Avatar
 
Member Since: Jan 12, 2009
Location: Prague, Czech Republic
Posts: 1,096
scathe is a jewel in the roughscathe is a jewel in the rough
Mac Specs: 2,4Ghz 15" unibody

scathe is offline
well the if syntax is the following:
if condition then
what_you_want_to_do
end if

I would help you out with putting the whole script together, but I don't have my Mac at the moment - only a linux system - and I have no idea when I get my Mac back.

hopefully I will remember to get back to this post in the future
QUOTE Thanks
skary

 
Member Since: May 17, 2010
Posts: 3
skary is on a distinguished road

skary is offline
okay. i got a bit closer. the time was 8:50 PM

Code:
on run {input, parameters}
	
	set CurTim to (time string of (current date))
	
	if the CurTim is greater than 1 then
		tell application "Finder" to shut down
	else
		null
	end if
	
	return input
end run
this will shut down the cpu as was made evident by it asking me if i wanted to save a textedit document. cancel of course canceled the shutdown as well.

Code:
on run {input, parameters}
	
	set CurTim to (time string of (current date))
	
	if the CurTim is greater than 9 then
		tell application "Finder" to shut down
	else
		null
	end if
	
	return input
end run
this did not shut down the cpu because it wasn't greater than 9:00 PM. So I think i can safely assume that a single digit will act as the hour.

now i need to be able to specify a time of 1:30 PM without getting an error on the colon ":".

and i also need to specify a range. Between 1:30 PM and 5:30 PM
QUOTE Thanks
scathe

 
scathe's Avatar
 
Member Since: Jan 12, 2009
Location: Prague, Czech Republic
Posts: 1,096
scathe is a jewel in the roughscathe is a jewel in the rough
Mac Specs: 2,4Ghz 15" unibody

scathe is offline
use quotes to override the colon: "1:30" - hopefully it will work, you might need to look for string comparing functions. Although I would look for a way to store it as a digit/integer and not a string ... If you can format the time to be in 24h format, then you don't need to worry about the colon, since 1:30 would be 0130

to use a conditional for your range do the following:
if (CurTim>0130) and (CurTime<0900) then
QUOTE Thanks

Post Reply New Thread Subscribe


« Develop on-device (iPod Touch) | cilk language installation error »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting 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 Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Long Shutdown Time of MacBook Pro... Tomlija OS X - Operating System 6 04-02-2010 12:01 AM
Automatic Shutdown While in Sleep Mode? johnwfisher OS X - Apps and Games 0 09-16-2009 12:39 PM
Unable to Shutdown SmokingFetus OS X - Operating System 11 10-14-2008 10:54 PM
Kernal panic in shutdown - OS 10.4 powercat OS X - Operating System 9 05-19-2005 10:14 AM
"shutdown -fh now" vs. the power button crouching.tiger OS X - Development and Darwin 2 09-02-2004 09:53 PM

All times are GMT -4. The time now is 01:12 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?