I’ve tried all the ‘first responder’ lines of script from these topics that I could find, but they all crash.
I simply want to place the cursor at the end of some numbers that are automatically inserted in a text field. Can anyone guide me on this please?
Regards
Santa
if not bypass2 then
set theSound to (load sound "/System/Library/Sounds/Glass.aiff")
play theSound
delete theSound
repeat 5 times
set contents of text field "messages" of theWindow to ""
delay 0.1
set contents of text field "messages" of theWindow to "The folder " & FileToFind & " couldn't be found."
delay 0.2
end repeat
else
set contents of text field "messages" of theWindow to ¬
"Open the graphics file, remove any excess graphics, then click the 'start automatic processing' box."
set contents of text field "Finished Name" of theWindow to FileToFind
-- I'd like to select after the inserted text above
if SoundFlag = 0 then
set SoundFlag to 1
my SetSound()
end if
end if
if not bypass2 then
set theSound to (load sound "/System/Library/Sounds/Glass.aiff")
play theSound
delete theSound
repeat 5 times
set contents of text field "messages" of theWindow to ""
delay 0.1
set contents of text field "messages" of theWindow to "The folder " & FileToFind & " couldn't be found."
delay 0.2
end repeat
else
tell theWindow
set contents of text field "messages" to ¬
"Open the graphics file, remove any excess graphics, then click the 'start automatic processing' box."
set first responder to text field "Finished Name"
call method "insertText" of (call method "currentEditor" of text field "Finished Name") with parameter FileToFind
end tell
if SoundFlag = 0 then
set SoundFlag to 1
my SetSound()
end if
end if
there is a «class conV» in the reference displayed by the error message, so the text field is no direct element of the window.
I recommend to check the reference
Thanks Stefan, the (first) bug lay with me, I had labelled the view instead of the window. Not used to Xcode 3.
However, it still doesn’t work. Using the script below in the ‘on end editing’ block, the cursor shows up in the second text box for the 4 seconds I’m temporarily delaying for, then the focus switches back to the original ‘Search’ box. The variable text does not get entered in the second box. I even tried putting the routine outside the ‘if’ loop as you can see.
I’m obviously still doing something the wrong way.
(Just in case you’re wondering, the folder names they search for are always job numbers, hence me checking the entry as a number first)
Any advice welcome.
Regards
Santa
on end editing theObject
set flag to false
if name of theObject = "Search" then
set FileToFind to content of theObject
set bypass to false
try
set FileToFind to FileToFind as number
on error
set bypass to true
tell application "Finder"
display dialog "That entry was not recognizable as a number" buttons "OK" giving up after 20
end tell
end try
if not bypass and FileToFind ≠0 then
set FileToFind to FileToFind as text
set bypass2 to false
tell application "Finder"
set temp to every folder of entire contents of alias TheServerDisk
repeat with CycleFolders in temp
if name of CycleFolders as text = FileToFind as text then
set bypass2 to true
open CycleFolders
end if
end repeat
end tell
if not bypass2 then
set theSound to (load sound "/System/Library/Sounds/Glass.aiff")
play theSound
delete theSound
set SetFlash to true
my Showmessage("The folder " & FileToFind & " couldn't be found.")
else
my Showmessage("Open the graphics file, remove any excess graphics, then click the 'start automatic processing' box.")
set flag to true
if SoundFlag = 0 then
set SoundFlag to 1
my SetSound()
end if
end if
end if
end if
if flag then
tell theWindow
set first responder to text field "Finished Name"
call method "insertText" of (call method "currentEditor" of text field "Finished Name") with parameter FileToFind
delay 4
end tell
end if
if name of theObject = "Finished Name" then
if (integer value of button "ignore" of window 1) = 1 then
set SoundFlag to 1
set FileToFind to content of theObject
end if
end if
if name of theObject = "Initials" then
my SetPreferences()
end if
end end editing
Stefan, i couldn’t get your routine to work at all, even when i tried the script below to trap the return key press, your line of code only inserted the cursor in the second field, not the required text.
However, I found some other routines, and the following works in a keyboard up trapping.
Regards
Santa.
on keyboard up theObject event theEvent
set theKeyPressed to (character of theEvent)
if the name of theObject is "Search" then
if theKeyPressed is return then
tell theWindow
set first responder to text field "Finished Name"
set txEd to (call method "currentEditor" of text field "Finished Name")
set selectedRange to (call method "selectedRange" of txEd)
call method "replaceCharactersInRange:withString:" of txEd with parameters {selectedRange, KeyPressString}
--call method "insertText" of (call method "currentEditor" of text field "Finished Name") with parameter KeyPressString
end tell
else
set KeyPressString to KeyPressString & theKeyPressed
end if
end if
end keyboard up