Can't describe in words...

I have a script. It doesn’t work. :frowning: The items are commented on what they are in the .xib file.

Script

--  Log
--  Created by Dylan Weber on Friday, February 26, 2010.
--  Copyright 2010 Dylan Weber. All rights reserved.

script LogAppDelegate
	property textView : missing value -- a text view
	property textfield : missing value -- multi-line text field
	property mainwin : missing value -- main window
	property namefield : missing value -- name text field
	property namewin : missing value -- name window
	
	on awakeFromNib()
		textView's setTextContainerInset_({10.0, 10.0})
		myname()
		textfield's setStringValue_("To begin logging, press \"Return\" on your keyboard.")
		mainwin's makeFirstResponder_(textfield)
	end awakeFromNib
	
	
	on action_(sender)
		set thetext to textfield's stringValue() as string
		textfield's setStringValue_("")
		set thename to myname()
		if thename is not false then
			textView's setString_(history & return & "Please enter a name in the name field in \"File\" → \"Name\"")
		else
			set history to history & reutrn & thename & " wrote \"" & thetext & " at " & (current date) as string
			textView's setString_(history)
		end if
	end action_
	
	on updatename_(sender)
		myname()
	end updatename_
	
	on myname()
		set thename to namefield's stringValue() as string
		if thename is "" then
			namewin's makeKeyAndOrderFront_(me)
			namewin's makeFirstResponder_(namefield)
			return false
		else
			return thename
		end if
	end myname
end script

Where does history come from?

I was going to set that up once the awakeFromNib() worked. :confused:

Here is an update that DOESN’T SOLVE MY PROBLEM.

Script

--  Log
--  Created by Dylan Weber on Friday, February 26, 2010.
--  Copyright 2010 Dylan Weber. All rights reserved.

script LogAppDelegate
	property textView : missing value -- a text view
	property textfield : missing value -- multi-line text field
	property mainwin : missing value -- main window
	property namefield : missing value -- name text field
	property namewin : missing value -- name window
	property history : ""
	
	on awakeFromNib()
		textView's setTextContainerInset_({10.0, 10.0})
		myname()
		textfield's setStringValue_("Type here!")
		mainwin's makeFirstResponder_(textfield)
	end awakeFromNib
	
	
	on action_(sender)
		set thetext to textfield's stringValue() as string
		textfield's setStringValue_("")
		set thename to myname()
		if thename is not false then
			textView's setString_(history & return & "Please enter a name in the name field in \"File\" → \"Name\"")
		else
			set history to history & return & thename & " wrote \"" & thetext & "\" at " & (current date) as string
			textView's setString_(history)
		end if
	end action_
	
	on updatename_(sender)
		myname()
	end updatename_
	
	on myname()
		set thename to namefield's stringValue() as string
		if thename is "" then
			namewin's makeKeyAndOrderFront_(me)
			namewin's makeFirstResponder_(namefield)
			return false
		else
			return thename
		end if
	end myname
end script

Help? :frowning:

Here is the project:
Log Project.zip (2.2 MB)

First, you had connected the text view property to the scrollview that contains the text view.

Download the corrected project here to see the other changes I made to get it to work.

Let me know if you have any questions.

Dylan,

See the next entry. I didn’t find a link to your project ? Did I miss that ?

[code](*
Forgot to :

( A ) do a performClose_(sender) in updateName_ so that the window will close 
       when you tab out of the nameField without having to click on a button
 ( B ) Added one extra step after step ( 4 ), a new step ( 5 )

*)

– Log
– Created by Dylan Weber on Friday, February 26, 2010.
– Copyright 2010 Dylan Weber. All rights reserved.
(*
Notes :
( 1 ) I renamed the namewin to nameWindow (not required, just easier for me)
( 2 ) renamed your action_ to _updateItems (not required, just easier for me)
( 3 ) IN IB do a (CMD-SHIFT_L), then type LogApp in the search field at the bottom
you should see the LogAppDelegate Class there, drag it over to .xib window
Once you do that if you select the (Log App Delegate Icon) and do (CMD-6)
You should see that the Class field contains LogAppDelegate

( 4 ) control-drag from mainWindow textField to controller (Log App Delegate Icon) and select _updateItems

-- added next step
( 5 ) control-drag from nameWindow nameField to controller (Log App Delegate Icon) and select _updateName

( 6 ) control-drag from the controller (Log App Delegate Icon) in the MainMenu.xib Doc window
			to the textView, and make sure you don't select the NSScrollView. (if you drag to the very top 
			of the NSScrollView the NSTextView (the first line of the NSScrollView) will highlight
( 5 ) Your if statement was backwards so I changed "if thename is not false then" to "if thename is false then"

*)
script LogAppDelegate
property mainWindow : missing value – main window
property textView : missing value – a text view
property textfield : missing value – multi-line text field

property nameWindow : missing value -- name window
property namefield : missing value -- name text field
property history : ""

on awakeFromNib()
	set history to (current date) as string -- [NSDate date]
	textView's setTextContainerInset_({10.0, 10.0})
	myname()
	textfield's setStringValue_("Type here!")
	mainwin's makeFirstResponder_(textfield)
end awakeFromNib


on updateItems_(sender)
	set thetext to textfield's stringValue() as string
	textfield's setStringValue_("")
	set thename to myname()
	if thename is false then
		textView's setString_(history & return & "Please enter a name in the name field in \"File\" → \"Name\"")
	else
		set history to history & return & thename & " wrote \"" & thetext & "\" at " & (current date) as string
		textView's setString_(history)
	end if
end updateItems_

on updatename_(sender)
	myname()
end updatename_

on myname()
	set thename to namefield's stringValue() as string
	if thename is "" then
		nameWindow's makeKeyAndOrderFront_(me)
		nameWindow's makeFirstResponder_(namefield)
		return false
	else
		nameWindow's performClose_(me) -- forgot this the first time
		return thename
	end if
end myname

end script[/code]
Good Luck,

Bill Hernandez
Plano, Texas

I want to make

history & return & userName & " wrote \"" & thetext & "\" at " & ((current date) as string)

into

userName & " wrote \"" & thetext & "\" at " & ((current date) as string) & return & history

How do I do that? I didn’t work for me.

Thanks. Ughhhhhhh. Now for more work on something so simple. Wait! How do I made the NSTextView non-editable?

Select the NSTextView and uncheck Editable in Interface Builder under Attributes.

Ah… Thanks Craig. You help everyone.

You’re welcome. :cool:

What did I do wrong this time? It says “2010-02-27 17:44:56.223 Log[4149:a0f] Can’t make current application into type «class fsrf».”
I need this to work.

Note: The password has been censored, so you’re going to have to find a way around that.

Script

--  Log
--  Created by Dylan Weber on Friday, February 26, 2010.
--  Copyright 2010 Dylan Weber. All rights reserved.

script LogAppDelegate
	property textView : missing value -- a text view
	property textfield : missing value -- multi-line text field
	property mainwin : missing value -- main window
	property namefield : missing value -- name text field
	property namewin : missing value -- name window
	property userName : missing value
	property history : ""
	
	
	on awakeFromNib()
		set history to do shell script "curl ftp://dylanweber:mypassherethatsfake@mactweaks.info/chat/chat.txt" as string
		textView's setTextContainerInset_({10.0, 10.0})
		textfield's setStringValue_("Type here!")
		mainwin's makeFirstResponder_(textfield)
	end awakeFromNib
	
	
	on action_(sender)
		set thetext to textfield's stringValue() as string
		textfield's setStringValue_("")
		
		if userName is in {"", missing value} then
			textView's setString_("Please enter a name in the name field." & return & history)
			myname()
		else
			set history to (userName as string) & " wrote \"" & thetext & "\" at " & ((current date) as string) & return & history
			textView's setString_(history)
			set result_ to upload(history, "Dylan's Laptop:Users:dylanweber:Library:Application Support:Messaging:chat.txt", "ftp://dylanweber:mypassherethatsfake@mactweaks.info/chat/chat.txt")
			set history to do shell script "curl ftp://dylanweber:mypasswordherethatsfake@mactweaks.info/chat/chat.txt" as string
			if result_ is false then
				textView's setString_("An error has occured during your chat." & return & history)
			end if
		end if
	end action_
	
	on updatename_(sender)
		myname()
	end updatename_
	
	on myname()
		set userName to namefield's stringValue()
		if userName is in {"", missing value} then
			namewin's makeKeyAndOrderFront_(me)
			namewin's makeFirstResponder_(namefield)
		else
			namewin's performClose_(me)
		end if
	end myname
	
	on upload(this_data, target_file, theURL)
		try
			set target_file to target_file as Unicode text
			if target_file does not contain ":" then set target_file to POSIX file target_file as Unicode text
			set the open_target_file to open for access file target_file with write permission
			set eof of the open_target_file to 0
			write this_data to the open_target_file starting at eof as string
			close access the open_target_file
			tell application "URL Access Scripting" to return upload target_file to theURL replacing yes
		on error e
			try
				close access file open_target_file
			end try
			log e
			return false
		end try
	end upload
end script

Help?

No help?

Wrap your write to file method with tell current application.
I thought you had watched my videos. :wink:

I got it working, but It is just not going right. It might, and might not.