Greetings,
My first post here. Trying to figure out how to call the method, currentCursor, to get the cursor.
Thanks
Greetings,
My first post here. Trying to figure out how to call the method, currentCursor, to get the cursor.
Thanks
At a basic level, all you need to do is call…
set theCursor to (call method "currentCursor" of class "NSCursor")
How you then deal with the cursor is a bit more complicated. You could simply do something like…
set theCursor to (call method "currentCursor" of class "NSCursor")
if (theCursor is equal to (call method "arrowCursor" of class "NSCursor")) then
-- Do something
end if
If you’re going to be doing a lot of referencing of many cursor types, you may want to save a persistent list of cursors to match against. I’m not sure you’d gain anything performance-wise by doing it this way, but it was a fun exercise so I thought I’d post it. It might be faster to just get the cursors as necessary, especially if you only want to do a couple tests.
property availableCursors : {}
on clicked theObject
if name of theObject is "button" then
set theCursor to (call method "currentCursor" of class "NSCursor")
set cursorName to nameOfCursor(theCursor)
if cursorName is not "" then display dialog ("Current Cursor: " & cursorName)
end if
end clicked
on will finish launching theObject
initCursors()
end will finish launching
to nameOfCursor(testCursor)
repeat with cursorRecord in availableCursors
set {cursorName, cursorObject} to cursorRecord
if cursorObject is testCursor then return cursorName
end repeat
return ""
end nameOfCursor
to initCursors()
set cursorList to {"arrowCursor", "closedHandCursor", "crosshairCursor", "disappearingItemCursor", "IBeamCursor", "openHandCursor", "pointingHandCursor", "resizeDownCursor", "resizeLeftCursor", "resizeLeftRightCursor", "resizeRightCursor", "resizeUpCursor", "resizeUpDownCursor"}
repeat with cursorName in cursorList
set cursorObject to (call method cursorName of class "NSCursor")
copy {cursorName, cursorObject} to the end of availableCursors
end repeat
end initCursors
on my computer it just says “theCursor is not defined”
is there any way to change what cursor it is?
thanks
Yay! This code looks to be a great source of increasing understanding. Going to start fiddling with it right away. Thanks!
jobu,
Hmm. What if a program has custom cursors and I don’t know what they are called? Is there a way to get the name or anything to distinguish one custom cursor from another?
Thanks