how can i check if the script is first run of day

is there a way that i can do something when the script runs only for the first time of day.

ok, basically i want finder to make a folder, which i think i know how to do, with the name set to the date, but only when the script is run the first time in any given day.

So say if on monday i ran the script it would create a folder called monday and all the files that i work in will be moved there. Then on tuesday at 10pm i run the script and it makes a folder called tuesday and then all the files i work on will be placed there.

to get the move, i am just going to place the folder nameinto a textdocument and call that as a variable, so when the code first runs that txt doc will get chaneged with the new folder name

Would something like this work? I’m not 100% sure what you want since you mentioned both the date and day as folder names.

set day_ to weekday of (current date)
set target_ to "path:to:location:for:new:folders:"

tell application "Finder"
	if exists folder (target_ & day_ & ":") then
		-- it has already been created
	else
		make new folder at folder target_ with properties {name:day_}
	end if
end tell

– Rob

thats right yeah.

I’ll check it and let you know.



set day_ to weekday of (current date)

set target_ to "Shared G4 HD:Users:karrenmay:Desktop:temp:"

tell application "Finder"

	if exists folder (target_ & day_ & ":") then
		-- it has already been created 
	else
		make new folder at folder target_ with properties {name:day_}
	end if
end tell


It doesn’t work. It creates an untitled folder. It should creae a folder called thu, as its thursday now.

Also can i format the date to give me:
dd/mm/year
???
if so how please

Hi Dave, in the terminal.app. see…

man strftime

From there you can do…

--do shell script "date +%d/%m/%Y" -- 14/08/2003
--do shell script "date +%d:%m:%Y" -- 14:08:2003
--do shell script "date +%m-%d-%Y" -- 08-14-2003
--do shell script "date +%m-%d-%Y-%H:%M:%S" -- 08-14-2003-04:45:12

to manipulate the date into any format you like.

Of course, don’t try to name a folder or file with a colon (“:”) in it, it’s reserved for path delimiters. Forward slash (“/”) should also be avoided I think but somehow the OS handles this better.

Jon

i have tried wht you said john, and here is my code now, it throws an error which i will also post:


try
	set day_ to do shell script "date + %m-&d-%Y"
	set target_ to "Jessica HD:Users:karrenm:Desktop:Pls Print Me:"
	
	tell application "Finder"
		
		if exists folder (target_ & day_ & ":") then
			-- it has already been created 
		else
			make new folder at folder target_ with properties {name:day_}
		end if
	end tell
on error theError
	set the clipboard to theError
end try

The error that is passed:


sh: d-%Y: command not found
date: illegal time format
usage: date [-nu] [-r seconds] [+format]
       date [[[[[cc]yy]mm]dd]hh]mm[.ss]

I’m guessing i did a typo or something but cant see it. Any ideas?

have just looked for the man page and it says:

No manual entry for strftime

does that mean i cant?

i look im the terminal

Change

to

(remove the space after the plus sign and change the ampersand in front of the “d” to a percent symbol).

Jon

have just tried what you said and it didnt through the same error:

But it did through this:

sh: d-%Y: command not found

???

Did you change the ampersand?

Jon

i’m such a knob, sorry i didn’t thought that i just copied and pasted, obviously not.

Hmmmmmm. :oops: :oops: :oops:

And it creates the folder too, wohoo!!!

Mac OS X, just does a straight swap. Any path that uses “/” as path delimiter will allow the “:” as a character in any part of the path file name, and vice versa. When using a traditional Mac OS “:” delimited based path the OS will replace any “:” in the file or path name with a slash, and working the other way does the opposite. This has some interesting implications when converting paths manually from one format to the other, which is one of the reasons why using the POSIX file and POSIX path commands is much safer.

This can be easily verified using terminal. I had to read the developer docs on this v.carefully when having to pass windows paths in a Mac OS app that was being updated from Mac OS to Mac OS X.

Kevin

“strftime” is in man3 which is not formatted by default to save space. There are 9 man files in /usr/share/man/ In order to use the other man files, you’ll need to format them by using the ‘catman’ command…

% cd /usr/share/man/
% sudo catman 3

The OS may make a swap of the delimiter at some level but from the Finder or AppleScript, you cannot add a colon to a file or folder name but a slash is added without problem:

Jon