SAP Script: Set focus on Input Field in order to SendKeys - user-interface

in my SAP VBS Script, I want to paste the Clipboard to an Input Field. I use
WshShell.SendKeys "^V", but it does not do anything and I suspect this because the Input Field has no focus.
So far my best guess was to "write" empty text into the field and then set the caret position to 0 and hope that this shifts focus to the field, but it does not help:
session.findById("wnd[0]/usr/ctxtRMMG1-MATNR").text = ""
session.findById("wnd[0]/usr/ctxtRMMG1-MATNR").caretPosition = 0
I have not found any methods for the session object, I hoped to find anything like session.setFocus or similar.
Is there a way to set focus on an Input Field?
Thanks

How about, for example, with
session.findById("wnd[0]/usr/ctxtRMMG1-MATNR").setfocus
Regards,
ScriptMan

Related

How to replace in selection using AppleScript for BBEdit?

Is there a way to replace text within a selection using Applescript for BBEdit? I have a replace script, and I'd like to run it for only selected text. I know you can replace in selection using the find menu, but I can't find anything that says it does this in the AppleScript dictionary for BBEdit. Thanks.
To use an application's scripting dictionary, specific commands aren't necessarily declared, just their syntax and options. Usually you can look at a command to see what the parameters are, which also defines the data types that it is expecting - in this case for example, the replace command has a searching in parameter, which can be anything.
The answer is similar to the one to your other topic, you just need to further define where to search. For example, the selection is a property of a window, and a window is a property of a document:
tell application "BBEdit"
tell front document
replace "12:" using "{#pl}:" searching in its window's selection
end tell
end tell

Xcode AppleScript : change label which content of variable

Here is my script :
property MyLabel : missing value
on buttonClicked_(sender)
set the plistfile_path to "~/Desktop/MY_DATA.plist"
tell application "System Events"
set p_list to property list file (plistfile_path)
-- read the plist data
set theMyDataFromPlist to value of property list item "DATA1" of p_list
end tell
end buttonClicked_
This gonna take the data I want from a plist and set in a variable (theMyDataFromPlist).
How can I print this variable on the label "MyLabel" and make the script auto refresh when the data change ?
also, when I click on the text (or another button), can I copy the value to the clipboard. (would set the clipboard to theMyDataFromPlist work?)
I also wonder is that possible to do the same with Swift?
How can I print this variable on the label "MyLabel"
Where would you like to print the variable? You can make AppleScript display a dialog:
set variable to 42
display dialog "The value of variable is " & variable
AppleScript is not designed as a terminal language, it is for UI scripting, so it's not like most scripting languages that just offer a print as where would the user see the printed value.
and make the script auto refresh when the data change ?
Not quite sure what you expect here. That your system magically runs your script whenever the content of a file changes? That's not going to happen. You can create a launchd job and have launchd monitor that file and then execute your script when the file changes; this is described here:
https://discussions.apple.com/message/13182902#13182902
But some process will have to monitor the file and if your script should do so, it has to be running all the time, non-stop. Then you could make some code run once every X seconds, checking the file last modification date and whenever that changes, re-read the plist. This polling is super ugly but the best thing that AS can do out of the box.
BTW where is the rest? You say
also, when I click on the text (or another button),
can I copy the value to the clipboard.
Which text? Which button? Sound like you have a whole application there but all you showed us are 11 lines script code. You didn't even mention that you have a whole application with a UI. Your question starts with "Here is my script", so you make it sound like this 11 lines is all that you have.
(would set the clipboard to theMyDataFromPlist work?)
Why don't you simply try it out? Pasting that line into ScriptEditor would have taken equally long than asking this question. I just tried it and it turns out that you can only set strings.
This code won't work:
-- bad code
set variable to 42
set the clipboard to variable
But this code does work:
-- good code
set variable to 42
set the clipboard to "" & variable
I also wonder is that possible to do the same with Swift?
Personally I would not even consider writing an application in AppleScript; I'd rather stop writing code before I do that. Of course this can be done in Swift or in Obj-C. Everything you can do in AS can be done in these other two languages and no, the opposite doesn't hold true.
Using Obj-C or Swift, you can also use GCD and with GCD monitoring a file for changes is easy. Just see
https://stackoverflow.com/a/11447826/15809

SEND clip as keystrokes

I am just wondering if there is any way in manner of PSH or VBS to paste/SEND the text from clipboard as separate keystrokes rather then string????
It is VERY important, since I have to do some automatic search in web UI drop down lists and passing text by CTRL+V simply does not work. So I need to send each letter as unique keystrokes.
Tried to find some way and searched over the Internet but no luck.
Thank you in advance
There are a few ways to interact with the clipboard in VBScript. Here's one way to read clipboard text:
strText = CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("text")
Once you have the text, you could simply send each letter in sequence:
For i = 1 To Len(strText)
SendKeys Mid(strText, i, 1)
Next

Set Value for ace editor without selecting the whole editor

So you can set value of an ace editor with setValue but after setting the value, the editor will select the whole value of the editor. How do you disable this? This mean when I set value of ace editor to Hello world, it won't highlight Hello world
You can use the second parameter to control cursor position after setValue
editor.setValue(str, -1) // moves cursor to the start
editor.setValue(str, 1) // moves cursor to the end
You can even use clearSelection() after you do an setValue();
editor.setValue("Hello World");
editor.clearSelection(); // This will remove the highlight over the text
I'm not sure if editor.setValue() is a remnant from the old days or what, but the proper way to set an editor's content is
editor.session.setValue(text);
or
editor.getSession().setValue(text);
This will NOT select the text, so there's no need to do any of the things mentioned on this page.
editor.setValue() explicitly selects all (and forgets to unselect it); but there's no reason to use it.
This works for me!
editor.setValue(editor.getValue(), 1);
I've been having your same issue.
Even though you can set the second parameter to either 1 or -1, I think you should also check this: https://ace.c9.io/api/editor.html#Editor.setValue
Editor.setWrapBehavioursEnabled(Boolean enabled)
Use this right after creating the editor.
This works very well for me.
The difference between this method and the one shared by a user is that the caret's position is not changed, you can move it yourself using Editor.selection.moveTo(row, column), this way the user won't experience weird caret position changes when using, say, CTRL+Z to undo an action :)
var prevtext = $("#editor").val();
prevtext = prevtext + "<br/>";
$("#editor").val(prevtext).blur();

How to display the text file while clicking the button

How to display the file(*.txt) while clicking the command button
How to display the content of the file while clicking the button
Data's are stored in the text file, ex 1.txt
when am clicking the command buttion, 1.txt file will open and 1.txt data's should display
Add a textbox to a form, make it multiline=true, add a button to the form.
And in the buttons click handler add this:
Private Sub Button1_Click()
Dim iFile As Long
Dim strFilename As String
Dim strTheData as String
strFilename = "C:\1.txt"
iFile = FreeFile
Open strFilename For Input As #iFile
strTheData = StrConv(InputB(LOF(iFile), iFile), vbUnicode)
Close #iFile
text1.text=strThedata
End Sub
This will read the text in the file and add it to the textbox.
Edit: Changed the line that reading the content to be more robust as pointed out by MarkJ in this answer (Cred goes to to MarkJ to pointing out that.)
Stefan's answer contains a flaw: the code to read a text file into a string isn't very robust. It's a very common mistake - the same flawed code is on some excellent VB6 web sites. His code is
Open strFilename For Input As #iFile
strTheData = Input$(LOF(iFile), #iFile)
Close #iFile
Unfortunately this throws an error 62 "input past end of file" if the text file contains ASCII zero characters. Also it doesn't work in all countries (it throws an error for most strings in double byte character sets like Chinese or Japanese).
Perhaps those problems are a bit obscure: but there's better code to do this job in the VB6 manual (here), it's also three lines, and it never fails.
Open strFilename For Input As #iFile
strTheData = StrConv(InputB(LOF(iFile), iFile), vbUnicode)
Close #iFile
It looks more complicated: but actually the only difference is that the conversion from ANSI to Unicode is explicit rather than implicit. It runs just as fast, and it always works.
No offence intended, but it sounds like you need a beginners tutorial on VB6.
(I think this because you don't seem to be able to articulate exactly what you need help with, possibly because you don't know enough about what you're trying to do).
Googling for VB6 Tutorial will give lots of links, this one looks good
Hope this helps, and apologies if I'm wrong :)
To just open a file using the current default file handler try using the ShellExecute API function.
Here's an example.

Resources