Craig,
Thanks a million for the great tutorial, I thought it was awesomeâŠ
I am not an Objective C person, so I hope youâll get a chance to make some more AppleScriptObjC. I had started several AppleScript Studio projects and they were going fairly well, and now itâs gone.
Hopefully we can get by with minimal Objective C ?
Hereâs a couple of easy changes to the first tutorial script, hope it is useful for beginners.
Thanks Again,
Bill Hernandez
Plano, Texas
â
â tutorial_part_oneAppDelegate.applescript
â tutorial_part_one
â Created by Bill Hernandez on 10/13/09.
â Copyright 2009 mac-specialist.com. All rights reserved.
â ±--------±--------±--------±--------±--------±--------+
â NOTES :
â ±--------±--------±--------±--------±--------±--------+
â set time_stamp to my get_time_stamp(2)
â ( n ) â> format choices { 1, 2, 3 }
â ( 1 ) â> 2009.10.13
â ( 2 ) â> [ 2009.10.13 ] ( 07.14.43.PM )
â ( 3 ) â> 2009.10.13_07.15.15.PM
â ±--------±--------±--------±--------±--------±--------+
script tutorial_part_oneAppDelegate
â ±--------±--------±--------±--------±--------±--------+
â Inheritance
â ±--------±--------±--------±--------±--------±--------+
property parent : class âNSObjectâ
â Option double click on â> NSTextView
-- +---------+---------+---------+---------+---------+---------+
-- IBOutlets
-- Interface Builder considers an outlet as any
-- property with "missing value" as its value
-- +---------+---------+---------+---------+---------+---------+
property aWindow : missing value
property textView : missing value
property textField : missing value
property show_message : false
-- +---------+---------+---------+---------+---------+---------+
-- IBActions (button clicks)
-- Interface Builder considers an action as any
-- single parameter method ending with an underscore
-- +---------+---------+---------+---------+---------+---------+
on setTextViewFromTextField_(sender)
-- USER MODIFIABLE
set which_update_method to 1 -- choices { 1, 2 }
-- date_object and current_date (NOT USED FOR NOW)
set date_object to current date
set current_date to (date_object as string)
-- ( n ) ---> time_stamp format choices { 1, 2, 3 }
-- ( 1 ) ---> [2009.10.13](07.15.41.PM)
-- ( 2 ) ---> [ 2009.10.13 ] ( 07.14.43.PM )
-- ( 3 ) ---> 2009.10.13_07.15.15.PM
set time_stamp to my get_time_stamp(2) -- format choices { 1, 2, 3 }
if (which_update_method is 1) then
tell textField
set textFieldValue to get stringValue()
end tell
tell textView
set textViewValue to get |string|()
set newText to (textViewValue as string) & return & time_stamp & " | " & (textFieldValue as string)
setString_(newText)
end tell
-- THIS ALSO WORKSOUTSIDE OF THE TELL BLOCK
-- textView's setString_((textFieldValue as string) & return & (textViewValue as string))
(*
display dialog (textViewValue as string)
display dialog (textFieldValue as string)
*)
else
set previousText to textView's |string|()
set currentText to textField's stringValue()
tell class "NSString" of current application
set newText to its stringWithFormat_("%@%@%@%@", previousText, return, time_stamp & " | ", currentText)
end tell
textView's setString_(newText)
end if
if (show_message) then
display dialog (newText as string)
end if
end setTextViewFromTextField_
-- +---------+---------+---------+---------+---------+---------+
on get_time_stamp(which)
if (which is 1) then
set returnValue to do shell script "date '+[%Y.%m.%d](%I.%M.%S.%p)'"
---> [2009.10.13](07.15.41.PM)
else if (which is 2) then
set returnValue to do shell script "date '+[ %Y.%m.%d ] ( %I.%M.%S.%p )'"
---> [ 2009.10.13 ] ( 07.14.43.PM )
else if (which is 3) then
set returnValue to do shell script "date '+%Y.%m.%d_%I.%M.%S.%p'"
---> 2009.10.13_07.15.15.PM
else
-- which is 1 or anything else
set returnValue to do shell script "date '+[%Y.%m.%d](%I.%M.%S.%p)'"
---> [2009.10.13](07.15.41.PM)
end if
return returnValue
end get_time_stamp
-- +---------+---------+---------+---------+---------+---------+
-- Application
-- +---------+---------+---------+---------+---------+---------+
on awakeFromNib()
set time_stamp to my get_time_stamp(2) -- format choices { 1, 2, 3 }
tell textView
setTextContainerInset_({5.0, 5.0})
setString_(time_stamp & " | " & "Bill Hernandez")
end tell
tell textField
setStringValue_("Default text")
end tell
-- add this as the last item in the awakeFromNib handler
aWindow's makeFirstResponder_(textField)
end awakeFromNib
-- +---------+---------+---------+---------+---------+---------+
on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
end applicationWillFinishLaunching_
-- +---------+---------+---------+---------+---------+---------+
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
-- +---------+---------+---------+---------+---------+---------+
end script
Model: iMac 2.6 GHz Intel
AppleScript: Xcode 3.2.1
Browser: Safari 531.9
Operating System: Mac OS X (10.6)