Why can't I add these two strings together? - applescript-objc

on oneButtonClicked_(sender)
set faceNumber's setStringValue() to faceNumber's stringValue() & "1"
end oneButtonClicked_
I get this error: "Can’t make «class ocid» id «data optr000000000058B37BFF7F0000» into type list, record or text. (error -1700)"
faceNumber is a label and when the user clicks the button, I want to add string of "1" to it. So for example, if the user clicked the button 5 times

stringValue returns an NSString(wrong answer) CFString. You have to make a real AppleScript String to use it.
BTW your code set faceNumber's setStringValue() is not correct. The reasons are:
The Cocoa handlers are always using the underscore.
If you use the setter setStringValue() you don't need to use set x to
If you want to use setStringValue() you must give the parameter between the parentheses
Now put everything together:
on oneButtonClicked_(sender)
faceNumber's setStringValue_((faceNumber's stringValue) as string & "1")
end oneButtonClicked_
or (to have it clearer):
on oneButtonClicked_(sender)
tell faceNumber
set currentValue to (its stringValue) as string
setStringValue_(currentValue & "1")
end tell
end oneButtonClicked_
I hope you like the answer, after pressing the button twice you have an 11 at the end of the label.
Cheers, Michael / Hamburg

Related

autohotkey search for a partial match

Can someone help with my code searching for a partial match. I seem to be stuck here.
I would like type only the first few letters in a combo-box, hit enter, and store whatever I have typed as a variable. Then I want to check my variable against my list for the closest name that matches what I have typed. That becomes the new variable. How do I do this?
#singleInstance, Force
list =
(
Phone Numbers
Important People
Modification
Traffic Data
Tasks
Tracker
)
Gui, +alwaysontop
Gui +Delimiter`n
Gui, Add, ComboBox, vMyVar w200 h110 CHOOSE1 sort, % LIST
Gui, Add, Button, gGO Default x+5 w60 h20 , GO
Gui, show, y200, What do you want now?!
return
; Type first couple letters in box hit enter
GO:
Gui, Submit, nohide
Loop, parse, List, `n
{
; Search LIST for nearest match
;First partial match found
; MyVar := "A_loopfield"
MsgBox % InStr(A_loopfield, DoThis)
}
if MyVar = Phone Numbers
; Msgbox or Function ETC..
Try
#singleInstance, Force
list =
(
Phone Numbers
Important People
Modification
Traffic Data
Tasks
Tracker
)
Gui, +alwaysontop
Gui +Delimiter`n
Gui, Add, ComboBox, vMyVar w200 h110 CHOOSE1 sort, % LIST
Gui, Add, Button, gGO Default x+5 w60 h20 , GO
Gui, show, y200, What do you want now?!
return
; Type first couple letters in box hit enter
GO:
Gui, Submit, nohide
GuiControlGet, text_typed,, ComboBox1
StringLen, length, text_typed ; retrieves the count of how many characters are in the text typed
Loop, parse, List, `n
{
If (SubStr(A_LoopField, 1, length) = text_typed)
{
GuiControl, Choose, MyVar, %A_LoopField%
If (A_LoopField = "Phone Numbers")
MsgBox, Item 1
; ...
If (A_LoopField = "Traffic Data")
MsgBox, Item 6
break
}
}
return

strings in a list not properly being added to an empty string

Im making a calculator program, and I'm currently trying to get the user's input into a string. I was able to create a list based on the buttons they pressed. So if they pressed 5, the string would be '5', and if they pressed 8 after, it would be '58', etc. So for each time the person presses the button, I have that number added to a list, so in the last example the list would be ['5','8']. Im trying to get those into a string together, '58', but am having issues.
from Tkinter import *
root=Tk()
root.geometry('300x500')
root.configure(bg="gray")
root.title("Calculator")
typed_num=[]
def button_command(number):
typed_num.append(str(number))
string_num=''
for val in typed_num:
string_num+=typed_num
print string_num
startx=20
starty=60
one_button=Button(root, text="1", command=lambda:button_command(1), highlightbackground='gray').place(x=startx, y=starty)
two_button=Button(root, text="2", command=lambda:button_command(2), highlightbackground='gray').place(x=startx+60, y=starty)
three_button=Button(root, text="3", command=lambda:button_command(3), highlightbackground='gray').place(x=startx+120, y=starty)
four_button=Button(root, text="4", command=lambda:button_command(4), highlightbackground='gray').place(x=startx, y=starty+60)
five_button=Button(root, text="5", command=lambda:button_command(5), highlightbackground='gray').place(x=startx+60, y=starty+60)
six_button=Button(root, text="6", command=lambda:button_command(6), highlightbackground='gray').place(x=startx+120, y=starty+60)
seven_button=Button(root, text="7", command=lambda:button_command(7), highlightbackground='gray').place(x=startx, y=starty+120)
eight_button=Button(root, text="8", command=lambda:button_command(8), highlightbackground='gray').place(x=startx+60, y=starty+120)
nine_button=Button(root, text="9", command=lambda:button_command(9), highlightbackground='gray').place(x=startx+120, y=starty+120)
zero_button=Button(root, text="0", command=lambda:button_command(0), highlightbackground='gray').place(x=startx+60, y=starty+180)
root.mainloop()
Any and all help is greatly appreciated! The error returned is:TypeError: cannot concatenate 'str' and 'list' objects
You are attempting this concatenation here: string_num+=typed_num. You can use append if you want to add an item to list such as typed_num.append(string_num). You tried to add a list to a string, you can add a string to a list however. "+" can be also used but the other way around
The problem is caused because you want to add a list with a string, that operation is not possible, I think you want to do is concatenate for them you must change:
string_num+=typed_num
to
string_num+=val
A simple way to concatenate a string list is to join, for this it changes:
string_num=''
for val in typed_num:
string_num+=typed_num
print string_num
to:
print "".join(typed_num)

How to manage looping on this list on Applscript?

The list is in the form of:-
0:
https://url
1:
https://url
..... And so on.
How could I loop on this list. So I could fetch the number first without ":" and type it somewhere then fetch the url that comes after that number and type it elsewhere. Then end repeat if the list is over.
Or should I use records instead?
I am still a beginner using AppleScript. I tried many commands I mixed up but the computer keeps running the script nonestop and the activity monitor shows the applescript using 100% of the processor and huge amount of ram.
Appreciate any help.
Thank you
You didn't define what your list really looks like very well so I made an assumption on my answer below. If I was wrong, hopefully my answer will at least point you in the right direction. (or if I've gotten it wrong, but you can choose to reformat it to the way I suggested, that could still help)
on run
set theList to {"0:http://apple.com", "1:http://google.com"} -- my guess at what your list looks like.
repeat with anItem in theList
set anItem to anItem as string
set itemParts to myParseItem(anItem)
set tID to the_integer of itemParts as integer
set tURL to the_url of itemParts as string
end repeat
end run
on myParseItem(theItem)
set AppleScript's text item delimiters to ":"
set delimitedList to every text item of theItem
set newString to (items 2 thru -1 of delimitedList as string)
set AppleScript's text item delimiters to {""}
set theInt to item 1 of delimitedList
set theURL to newString as string
return {the_integer:theInt, the_url:theURL}
end myParseItem

Autohotkey if statement not working, no error msg

I'm trying to use autohotkey to gather a chuck of data from a website and then click a certain spot on the website depending on what the text is. I'm able to get it to actually pick up the value but when it comes to the if statement it won't seem to process and yields no error message. Here is a quick sample of my code, there is about 20 if statement values so for brevity sake I've only included a few of the values.
GuessesLeft = 20
Errorcount = 0
;triple click and copy text making a variable out of the clipboard
;while (GuessesLeft!=0) part of future while loop
;{ part of future while loop
click 927,349
click 927,349
click 927,349
Send ^c
GetValue = %Clipboard%
if ( GetValue = "Frontal boss")
{
click 955,485
Guessesleft -= 1
}
else if ( GetValue = "Supraorbital Ridge")
{
click 955,571
Guessesleft -= 1
}
;....ETC
else
{
Errorcount += 1
}
;} part of future while loop
Any tips on what I might be doing wrong. Ideally I'd use a case statement but AHK doesn't seem to have them.
Wait a second -- you are triple clicking to highlight a full paragraph and copying that to the clipboard and checking to see if the entirety of the copied portion is the words in the if statement, right? And your words in the copied portion have quotes around them? Probably you will have to trim off any trailing spaces and/or returns:
GetValue = % Trim(Clipboard)
If that doesn't work, you may even have to shorten the length of the copied text by an arbitrary character or two:
GetValue = % SubStr(Clipboard, 1, (StrLen(Clipboard)-2))
Now, if I am wrong, and what you are really looking for is the words from the if statement wherever they may be in a longer paragraph -- and they are not surrounded by quotes, then you will want something like:
IfInString, Clipboard, Frontal boss
Or, if the quotes ARE there,
IfInString, Clipboard, "Frontal boss"
Hth,

How to get dragged text position MFC

I'm trying to insert tag next to specific text.
I was get a knowhow to insert tag next to text..
It is to use Setsel() and ReplaceSel().
example,
char str = "< name >";
m_richedit.Setsel( position of start dragging of text, end position )
m_richedit.ReplaceSel( str, TRUE )
but, I don't know how to get position of start dragging of text in richEdit.
Is there anybody who has an idea?
Thank you.
You need to add the appropriate accelerator key like they explain here: Adding accelerators(shortcuts) in MFC - HOW? . Then in the handler of the accelerator key, use GetSelText, add your tags to the string you get and call ReplaceSel.