Craig,
Here are the .h, .m.and AppleScriptObjC files.
This works great.
I am glad you knew the answer to my questions.
Thanks Again…
Bill Hernandez
Plano, Texas
// ±--------±--------±--------±--------±--------±--------+
// [4325] ( BEGIN ) OBJECTIVE-C METHOD INTERFACE FILE
// The .h file:
// ±--------±--------±--------±--------±--------±--------+
// NSTextView+methods.h
// tutorial_part_one
//
// Created by Bill Hernandez on 10/14/09.
// Copyright 2009 mac-specialist.com. All rights reserved.
// ±--------±--------±--------±--------±--------±--------+
#import <Cocoa/Cocoa.h>
// ±--------±--------±--------±--------±--------±--------+
// This was the default text when I created the new
// ‘Objective-C Class’ File, so I commented it out
// ±--------±--------±--------±--------±--------±--------+
// @interface NSTextView_methods : NSObject {
//
// }
//
// @end
// ±--------±--------±--------±--------±--------±--------+
// ±--------±--------±--------±--------±--------±--------+
// METHOD INTERFACE TO EXTEND NSTextView by Craig Williams
//
// To add methods to any class you create a category.
//
// Add a new ‘Objective-C Class’ file to your project.
// Name it “NSTextView+methods.”
//
// Add a new method, Xcode creates two files (an interface file, and an implementation)
// ( 1 ) NSTextView+methods.h
// ( 2 ) NSTextView+methods.m
// ±--------±--------±--------±--------±--------±--------+
@interface NSTextView (methods)
-(NSString *)stringValue;
@end
// ±--------±--------±--------±--------±--------±--------+
// [4325] ( END ) OBJECTIVE-C METHOD INTERFACE FILE
// ±--------±--------±--------±--------±--------±--------+
// ±--------±--------±--------±--------±--------±--------+
// [4326] ( BEGIN ) OBJECTIVE-C METHOD IMPLEMENTATION FILE
// The .m file:
// ±--------±--------±--------±--------±--------±--------+
// NSTextView+methods.m
// tutorial_part_one
//
// Created by Bill Hernandez on 10/14/09.
// Copyright 2009 mac-specialist.com. All rights reserved.
// ±--------±--------±--------±--------±--------±--------+
#import “NSTextView+methods.h”
// ±--------±--------±--------±--------±--------±--------+
// This was the default text when I created the new
// ‘Objective-C Class’ File, so I commented it out
// ±--------±--------±--------±--------±--------±--------+
// @implementation NSTextView_methods
//
// @end
// ±--------±--------±--------±--------±--------±--------+
// ±--------±--------±--------±--------±--------±--------+
// METHOD IMPLEMENTATION TO EXTEND NSTextView by Craig Williams
//
// To add methods to any class you create a category.
//
// Add a new ‘Objective-C Class’ file to your project.
// Name it “NSTextView+methods.”
//
// Add a new method, Xcode creates two files (an interface file, and an implementation)
// ( 1 ) NSTextView+methods.h
// ( 2 ) NSTextView+methods.m
// ±--------±--------±--------±--------±--------±--------+
@implementation NSTextView (methods)
-(NSString *)stringValue
{
return [self string];
}
@end
// ±--------±--------±--------±--------±--------±--------+
// [4326] ( END ) OBJECTIVE-C METHOD IMPLEMENTATION FILE
// ±--------±--------±--------±--------±--------±--------+
– ±--------±--------±--------±--------±--------±--------+
– [4327] ( END ) AppleScriptObjC FILE
– ±--------±--------±--------±--------±--------±--------+
– 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 DoubleClick on —> NSTextView then click on the book icon
–Option DoubleClick on —> NSText then click on the book icon
-- +---------+---------+---------+---------+---------+---------+
-- 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, 3 }
-- 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 stringValue() -- USE THE NEWLY DEFINED METHOD
set newText to (textViewValue as string) & return & time_stamp & " | " & (textFieldValue as string)
setString_(newText)
end tell
else if (which_update_method is 2) 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 WORKS OUTSIDE OF THE TELL BLOCK
-- textView's setString_((textFieldValue as string) & return & (textViewValue as string))
else ---> (which_update_method is 3)
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
set x to textView's stringValue() -- USE THE NEWLY DEFINED METHOD
display dialog (x as string)
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
– ±--------±--------±--------±--------±--------±--------+
– [4327] ( END ) AppleScriptObjC FILE
– ±--------±--------±--------±--------±--------±--------+