Saturday, November 3, 2007

Make Note AppleScript


set newnote to (do shell script "pbpaste") as string
if (length of newnote is 0) then return "Zero length note"

-- GET THE CURRENT DATE TO GENERATE DEFUALT NAME --
set cdate to do shell script "date +%Y-%m-%d | tr -d '\\n'"

-- DISPLAY DIALOG TO GET THE NOTE NAME --
set reply to display dialog "You are about to create new note with text:
\"" & newnote & "\"

Enter note name:" default answer "Note " & cdate

-- GOT NAME --
if (length of reply > 0) then

set notename to text returned of reply as string
set cnt to 1 -- INITIALIZE COUNTER FOR PATH GENERATING
set fname to notename

-- GET FULL NAME FOR DIRECTORY --
set dir to (do shell script "echo -n $HOME") & "/Documents/-NOTES-/"

-- GENERATE NEW NAME --
repeat
set notepath to dir & fname as string

-- CHECK IF PATH EXISTS --
set tst to do shell script "test -f \"" & notepath & "\"; echo $?"
-- return (do shell script scr)
-- display dialog tst


if tst is not "0" then
exit repeat -- PATH NAME IS OK, SO EXIT LOOP
end if

-- ELSE ADD COUNTER TO NAME
set fname to notename & " " & (cnt as string)
set cnt to cnt + 1

end repeat

-- display dialog notepath

if (length of notepath > 0) then
-- PASTE CLIPBOARD TEXT INTO THE FILE --
do shell script "pbpaste > \"" & notepath & "\""
end if

end if

Current Date AppleScript

do shell script "date +%Y-%m-%d | tr -d '\\n'  | pbcopy"