Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

M-B-P

macrumors regular
Original poster
May 15, 2010
169
0
Hey,

I am trying to schedule the execution of an Applescript. The purpose is to create an new folder with the current day's date daily. I want to either schedule is so that when I start up my Mac the Applescript will run (a login item maybe??) or at a specified time of the day, daily.

This is what I have so far:

set {year:y, month:m, day:d, time string:t} to (current date)
set date_format to (y * 10000 + m * 100 + d) as string

set reformated_date to (text items 5 thru 6 of date_format as string) & "/" & (text items 7 thru 8 of date_format as string) & "/" & (text items 1 thru 4 of date_format as string)

tell application "Finder"
activate
make new folder at folder "Desktop" of folder "John" of folder "Users" of startup disk with properties {name:reformated_date}
end tell


Any thoughts?
 

M-B-P

macrumors regular
Original poster
May 15, 2010
169
0
As part of the same project, I need to get the current date and get it in the format of "Month Day, Year". So what I want is July 24, 2011, as a string so that I can add it to a file path. This is what I have so far:

set theDate to date string of (the current date)
--Returns "Sunday, July 24, 2011"

set AppleScript's text item delimiters to ", "
set theDateItemized to every text item of theDate
set dateWithoutDay to rest of theDateItemized
set AppleScript's text item delimiters to {""}

display dialog dateWithoutDay

It is probably a simple task, but I am new to applescript and programming in a whole, so I am learning little by little as I go along with these projects of mine.
 

neutrino23

macrumors 68000
Feb 14, 2003
1,881
391
SF Bay area
You can set an alarm in iCal that will run any script at the time you desire. In the popup menu for alarms one option is run script.

Off the top of my head I don't recall how to get the date as you like. I have this in a script I use a lot. I'll find it later today if no one else provides it. IIRC it is something like

Set xdate to (applescript's date)
Set xmonth to month of xdate
Set xday to day of xdate

And so on. The date returns as a structure and you can ask for each part as a string.
 

M-B-P

macrumors regular
Original poster
May 15, 2010
169
0
Thanks, didn't know that about iCal.

If I set the alarm to repeat daily at say 3:00 a.m. (when my Mac is usually turned OFF), will the script/alarm run once I turn on my mac?

Is there a way to hide the event on iCal, because it is annoying to have the repeat script event on my calendar.

About the date, I put something together and it seems to work. I didn't know how to set the variables to the string format, but figured it out. Here it is:

set {year:y, month:m, day:d, time string:t} to (current date)

set currMonth to m as string
set currDay to d as string
set currYear to y as string

display dialog currMonth & " " & currDay & ", " & currYear


One last thing, since you seem like you know what you are talking about. Is there a way to reformat text to combine all of the paragraphs into a single paragraph, kind of link undoing the effect of the "return" button. I am scanning documents, running OCR software, and need to combine the paragraphs into a single paragraph, either from a clipboard, text edit, or applescript itself.

Thanks for your help
 

MacGrunt

macrumors newbie
Jul 25, 2011
7
0
You could try something like this :
Code:
set thetext to WhateverYourTextInputIs

set newtext to ""
set AppleScript's text item delimiters to "
"
set thetext to (text items of thetext)
set AppleScript's text item delimiters to ""

repeat with x in thetext
	repeat until text item -1 of x is not " " --strip spaces from end of paras
		set x to text items 1 through -2 of x
	end repeat
	repeat until text item 1 of x is not " " --strip spaces from start of paras
		set x to text items 2 through -1 of x
	end repeat
	set newtext to newtext & x & " " --join paras together with a single space separating
end repeat
return newtext

m.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.