Autohotkey and Cisco Jabber - Click to call - clipboard

I followed this Tutorial (http://www.employees.org/~dhenwood/ClicktoCall.pdf1) to call a marked number (in a browser, in outlook, etc). Telephone numbers as links works fine, but when I mark numbers, it does not work. Here is the code:
$^D::clipboard = Send ^c
ClipWait,
clipboard = %clipboard%
StringReplace, tel, clipboard, %A_SPACE%, , All
tel := RegExReplace(tel, "\(.*\)", "")
Run, tel:%tel%
Return
When I press Ctrl+D it just make a copy of the text after "clipboard =" on the first line. In this example "Send ^c".

Give this a shot:
~$^D::
Send {ctrl down}{c down}{ctrl up}{c up}
ClipWait,
clipboard = %clipboard%
StringReplace, tel, clipboard, %A_SPACE%, , All
tel := RegExReplace(tel, "\(.*\)", "")
Run, tel:%tel%
Return

Related

Text outputs as multiple separate lines instead of one paragraph with linebreaks

I have a bot that writes my message to a webpage. I want the message to be sent as one paragraph, but with the lines separated by a linebreak. However, when I actually run the code, the bot inputs and enters each line separately, instead of as one paragraph
I've tried messing with the linebreak formatting and string formatting, but the issue persists
reply_messages = []
reply_messages.push([
"FREE BABY AVOCUDDLE - Thank you for your patience!",
"To redeem your FREE avocuddle, just use the LINK IN OUR BIO and ADD TO CART - just cover shipping, no additional charges!",
"Discount AUTOMATICALLY APPLIES! Super simple, no code!",
"If you order another avocuddle in addition, we cover shipping PLUS the free baby avocuddle! :)",
"Feel free to DM us if you need anything!"
].join("\n")+"\n")
.
.
.
while true
browser.get 'https://twitter.com/messages/requests'
sleep 5
request = wait.until {
el = browser.find_element(:css, "[data-testid='conversation']")
el if el.displayed?
}
break if request.nil?
request.click
not_acceptable_link = true
na_link_index = 1
while not_acceptable_link == true
accept_btn = browser.find_element(:xpath, "//*[contains(text(), 'Accept')]")
unless accept_btn.displayed?
request_2 = wait.until {
el = browser.find_elements(:css, "[data-testid='conversation']")[na_link_index]
el if el.displayed?
}
request_2.click
else
not_acceptable_link = false
end
na_link_index += 1
end
accept_btn = browser.find_element(:xpath, "//*[contains(text(), 'Accept')]")
accept_btn.click
sleep 1
reply_input = wait.until {
el = browser.find_element(:css, "[data-testid='dmComposerTextInput']")
el if el.displayed?
}
reply_input.click
reply_input.send_keys(reply_messages)
.
.
.
I would like for the code to output the entire text as one block of text. However, instead, it outputs as separate lines.
Output currently looks like:
FREE BABY AVOCUDDLE - Thank you for your patience!
(enters this into text box)
To redeem your FREE avocuddle, just use the LINK IN OUR BIO and ADD TO CART - just cover shipping, no additional charges!
(enters this into text box)
etc.
Instead I would like for it to send as one message.

Save text and output on textbox (Ruby Selenium/Webdriver)

I want to get a text from an element and then I want to write that text into another element which is available in another window when window switch.
Selenium::WebDriver::Chrome.driver_path="C:/chromedriver.exe"
browser = Selenium::WebDriver.for :chrome
browser.get 'https://docs.google.com/spreadsheets/d/1BJMqNGK1e2j4VjS8K2kS5wloKpEaHu_GTxMl2KueUCM/edit?usp=sharing'
sleep 8
browser.action.send_keys(:arrow_down).perform
browser.action.send_keys(:left_control, 'c').perform
sleep 1
browser.execute_script("window.open('http://10.19.252.220:25780/PortalCDT/')")
browser.window_handles.each do |handle|
browser.switch_to.window handle
end
sleep 5
browser.find_element(:id, "IdClient").click
browser.find_element(:id, "IdClient").send_keys(:left_control, 'v')
browser.find_element(:id, "ConfirmButton").click
puts "Disp. Cash: " + browser.find_element(:id, "ctl00_ContentPlaceHolder1_ucInfoCliente_lblDispCash").text
column4 = browser.find_element(:id, "ctl00_ContentPlaceHolder1_ucInfoCliente_lblDispCash").text
puts "-------------------------------------"
sleep 1
browser.window_handles.each do |handle|
browser.switch_to.window handle
sleep 1
browser.action.send_keys(:arrow_right).perform
browser.action.send_keys("Id Here").perform
browser.action.send_keys(:arrow_right).perform
browser.action.send_keys(:colunmn4).text
browser.window_handles.each do |handle|
browser.switch_to.window handle
sleep 1
browser.action.send_keys(:arrow_down).perform
browser.action.send_keys(:left_control, 'c').perform
end
browser.window_handles.each do |handle|
browser.switch_to.window handle
end
tried to save the text into column4 variable and then I want to write it into a text field which is another window.
Html code to copy text
<span id="ctl00_ContentPlaceHolder1_ucInfoCliente_lblDispRotativo">2870,14</span>
Thanks!
There are plenty of mistake in your program.
1)To pass,control+c, you should pass[:control,"c"], not like (:control, 'c'), The difference here is, your code would pass control and c sequentially but code [:control,'c'] would hold the control key while it presses c. Do you see the difference?
2)Why are you opening a new tab while you intend to open another url? Open another Browser, that would not need your shift in Window.
Since I can't open your second URL, I copy your intended cell from spreadsheet and paste it in Google search textfield.
require 'selenium-webdriver'
driver=Selenium::WebDriver.for :chrome
driver.navigate.to 'https://docs.google.com/spreadsheets/d/1FMOaVoDF3PsXCgqiEQgYWe8CCO7PcDwsqHpEGT2no3I/edit?usp=sharing'
driver.action.send_keys(:arrow_down).perform
driver.action.send_keys([:control, 'c']).perform
driver1=Selenium::WebDriver.for :chrome
driver1.navigate.to("https://www.google.com/")
driver1.action.send_keys([:control, 'v']).perform
Correct answer:
value = browser.find_element('span#ctl00_ContentPlaceHolder1_ucInfoClient_lblDispCash')
value_text = value.text
text_area = browser.find_element('textbox#whatver_id')
text_area.send_keys(value_text, :enter).perform

I need to URL-encode a string in AppleScript

My script searches a website for songs, but when there are spaces it doesn't search, you have to add underscores. I was wondering if there was a way to replace my spaces with underscores.
Could you please use my current code below to show me how to do it?
set search to text returned of (display dialog "Enter song you wish to find" default answer "" buttons {"Search", "Cancel"} default button 1)
open location "http://www.mp3juices.com/search/" & search
end
Note: The solution no longer works as of Big Sur (macOS 11) - it sounds like a bug; do tell us if you have more information.
Try the following:
set search to text returned of (display dialog "Enter song you wish to find" default answer "" buttons {"Search", "Cancel"} default button 1)
do shell script "open 'http://www.mp3juices.com/search/'" & quoted form of search
end
What you need is URL encoding (i.e., encoding of a string for safe inclusion in a URL), which involves more than just replacing spaces.
The open command-line utility, thankfully, performs this encoding for you, so you can just pass it the string directly; you need do shell script to invoke open, and quoted form of ensures that the string is passed through unmodified (to be URI-encoded by open later).
As you'll see, the kind of URL encoding open performs replaces spaces with %20, not underscores, but that should still work.
mklement0's answer is correct about url encoding but mp3juices uses RESTful URLs (clean URLs). RESTful URLs want's to keep the URL human readable and you won't see/use typical hex values in your url presenting an ASCII number. A snake_case, as you have mentioned (is false), but it is pretty common to use an substitution for whitespaces (%20) (and other characters) in RESTful URLs. However the slug of an RESTful must be converted to RESTful's own RESTful encoding before it can be handled by standard URL encoding.
set search to text returned of (display dialog "Enter song you wish to find" default answer "" buttons {"Search", "Cancel"} default button 1)
set search to stringReplace(search, space, "-")
do shell script "open 'http://www.mp3juices.com/search/'" & quoted form of search
on stringReplace(theText, searchString, replaceString)
set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, searchString}
set textItems to every text item of theText
set AppleScript's text item delimiters to replaceString
set newText to textItems as string
set AppleScript's text item delimiters to oldTID
return newText
end stringReplace
EDIT: updated the code, unlike the question mentioned that spaces are converted to underscores, mp3juice uses hyphens as substitution for whitespaces.
An update on this, despite the fact that the answer is 3 years old, as I faced the same problem: on recent versions of macOS/OS X/Mac OS X (I think, 10.10 or later), you can use ASOC, the AppleScript/Objective-C bridge:
use framework "Foundation"
urlEncode("my search string with [{?#äöü or whatever characters")
on urlEncode(input)
tell current application's NSString to set rawUrl to stringWithString_(input)
set theEncodedURL to rawUrl's stringByAddingPercentEscapesUsingEncoding:4 -- 4 is NSUTF8StringEncoding
return theEncodedURL as Unicode text
end urlEncode
It should be noted that stringByAddingPercentEscapesUsingEncoding is deprecated, but it will take some time until it’s removed from macOS.
URL encoding in AppleScript
For a general use case (for me at the moment to pass any ASCII url containing chars like #, &, ß, ö to the bit.ly API), I stumbled upon a nice code snippet that instantly added full support to my ShortURL clipboard pasting shortcut. Here's a quote from source:
i was looking for a quick and dirty way to encode some data to pass to a url via POST or GET with applescript and Internet Explorer, there were a few OSAXen which have that ability, but i didn't feel like installing anything, so i wrote this thing (works with standard ascii characters, characters above ascii 127 may run into character set issues see: applescript for converting macroman to windows-1252 encoding)
Notes
Double encoding should be duly noted.
Not tested on non-ASCII URLs.
Tested on OS X 10.8.5.
Code
on urlencode(theText)
set theTextEnc to ""
repeat with eachChar in characters of theText
set useChar to eachChar
set eachCharNum to ASCII number of eachChar
if eachCharNum = 32 then
set useChar to "+"
else if (eachCharNum ≠ 42) and (eachCharNum ≠ 95) and (eachCharNum < 45 or eachCharNum > 46) and (eachCharNum < 48 or eachCharNum > 57) and (eachCharNum < 65 or eachCharNum > 90) and (eachCharNum < 97 or eachCharNum > 122) then
set firstDig to round (eachCharNum / 16) rounding down
set secondDig to eachCharNum mod 16
if firstDig > 9 then
set aNum to firstDig + 55
set firstDig to ASCII character aNum
end if
if secondDig > 9 then
set aNum to secondDig + 55
set secondDig to ASCII character aNum
end if
set numHex to ("%" & (firstDig as string) & (secondDig as string)) as string
set useChar to numHex
end if
set theTextEnc to theTextEnc & useChar as string
end repeat
return theTextEnc
end urlencode
If you need to get the URL as a string (not just feed it into open which does a nifty job of encoding for you) and you're not above using a little Automator, you can throw some JavaScript into your AppleScript:
encodeURIComponent is a built in JavaScript function - it is a complete solution for encoding components of URIs.
For copy/pasters, here are all three scripts in the above Automator chain:
on run {input, parameters}
return text returned of (display dialog "Enter song you wish to find" default answer "" buttons {"Search", "Cancel"} default button 1)
end run
function run(input, parameters) {
return encodeURIComponent(input);
}
on run {input, parameters}
display dialog "http://www.mp3juices.com/search/" & input buttons {"okay!"} default button 1
end run
I was hunting around for URL encoding and decoding and came across this helpful link.
Which you can use like so:
set theurl to "https://twitter.com/zackshapiro?format=json"
do shell script "php -r 'echo urlencode(\"" & theurl & "\");'"
# gives me "https%3A%2F%2Ftwitter.com%2Fzackshapiro%3Fformat%3Djson"
set theurl to "https%3A%2F%2Ftwitter.com%2Fzackshapiro%3Fformat%3Djson"
return do shell script "php -r 'echo urldecode(\"" & theurl & "\");'"
# gives me "https://twitter.com/zackshapiro?format=json"
Or as functions:
on encode(str)
do shell script "php -r 'echo urlencode(\"" & str & "\");'"
end encode
on decode(str)
do shell script "php -r 'echo urldecode(\"" & str & "\");'"
end decode
Just so it's said, AppleScriptObjC allows us to use NSString to do the encoding. The script is complicated by the fact that different parts of the URL allow different characters (all of which I've added options for) but in most cases the 'query' option will be used.
See NSCharacterSet's dev page (the section called "Getting Character Sets for URL Encoding") for descriptions of the various URL parts.
use AppleScript version "2.4" -- Yosemite 10.10 or later
use framework "Foundation"
property NSString : class "NSString"
property NSCharacterSet : class "NSCharacterSet"
-- example usage
my percentEncode:"some text" ofType:"query"
on percentEncode:someText ofType:encodeType
set unencodedString to NSString's stringWithString:someText
set allowedCharSet to my charSetForEncodeType:encodeType
set encodedString to unencodedString's stringByAddingPercentEncodingWithAllowedCharacters:allowedCharSet
return encodedString as text
end percentEncode:ofType:
on charSetForEncodeType:encodeType
if encodeType is "path" then
return NSCharacterSet's URLPathAllowedCharacterSet()
else if encodeType is "query" then
return NSCharacterSet's URLQueryAllowedCharacterSet()
else if encodeType is "fragment" then
return NSCharacterSet's URLFragmentAllowedCharacterSet()
else if encodeType is "host" then
return NSCharacterSet's URLHostAllowedCharacterSet()
else if encodeType is "user" then
return NSCharacterSet's URLUserAllowedCharacterSet()
else if encodeType is "password" then
return NSCharacterSet's URLPasswordAllowedCharacterSet()
else
return missing value
end if
end charSetForEncodeType:
The Python Approach:
Find your python3 path (which python3) or if you don't have it, install using brew or miniconda
Now try this:
python_path = /path/to/python3
set search_query to "testy test"
tell application "Google Chrome"
set win to make new window
open location "https://www.google.com/search?q=" & url_encode(q)
end tell
on url_encode(input)
return (do shell script "echo " & input & " | " & python_path & " -c \"import urllib.parse, sys; print(urllib.parse.quote(sys.stdin.read()))\"
")
end url_encode
credits to #Murphy https://stackoverflow.com/a/56321886

gui display string manipulation

I am learning Python in the hope of impressing my grandchildren - hope nobody is at all ageist! My project is to get the Hangman game I wrote in QuickBasic to work under Windows7.
I have successfuly prepared a Hangedman figure and written routine to extract random word from a large csv file. Now I want to write the user interface but attempts to return to an already used location result in overwriting - I am unable to erase the existing string.
The routine following is to explore how to write a string at a given location and erase it for the purposes of the game:
# attempt to write and erase text at point locations
# all works OK until returned to location already used
#
# 23 FEB 14
from graphics import *
import tkinter
def main():
# make window
win = GraphWin("Display text locator", 600, 500)
# click 1 to start
win.getMouse()
# establish first location
output = Text(Point(400,400),"")
output.draw(win)
# and print simulated hangman word length
output.setText(" _ _ _ _ _ _ _ _ ")
# click 2 for first string replacement
win.getMouse()
output.setText(" ABCZYX W ")
# click 3 to blank out first string
win.getMouse()
output.setText(" ")
# click 4 to show new string
win.getMouse()
output.setText(" and here we are again ")
# click 5 points to new text location and display
win.getMouse()
output = Text(Point(100,100),"")
output.draw(win)
# first string at new location
output.setText(" here's the new position ")
# click 6 to show new string
win.getMouse()
output.setText(" blank that out ")
# click 7 to erase it
win.getMouse()
output.setText(" ")
# click 8 points back to first location
win.getMouse()
output = Text(Point(400,400),"")
output.draw(win)
# should blank out existing string (but fails)
output.setText(" - ")
# click 9 to display new string (but simply overwrites)
win.getMouse()
output.setText(" BACK TO THE FIRST POSITION ")
# click 10 exits
win.getMouse()
win.close()
main()
All suggestions gratefully received (provided no laughing!)
many thanks - jeremy/

I want AutoIt to activate a particular tab in Firefox. How can this be done?

I have several tabs open in Firefox. I want AutoIt to activate a particular tab in Firefox. How can this be done?
Give the whole browser window focus, then use the send command to repeatedly send it cntl-tab until the window's title is the name of the tab you want (with - Mozilla Firefox at the end).
There's a UDF (User Defined Functions -include file) called FF.au3. Looks like the function you want is _FFTabSetSelected(), good luck!
Below is an example of Jeanne Pindar's method. This is the way I would do it.
#include <array.au3>
Opt("WinTitleMatchMode", 2)
activateTab("Gmail")
Func activateTab($targetWindowKeyphrase)
WinActivate("- Mozilla Firefox")
For $i = 0 To 100
If StringInStr(WinGetTitle(WinActive("")),$targetWindowKeyphrase) Then
MsgBox(0,"Found It", "The tab with the key phrase " & $targetWindowKeyphrase & " is now active.")
Return
EndIf
Send("^{TAB}")
Sleep(200)
Next
EndFunc
Here you go...
AutoItSetOption("WinTitleMatchMode", 2)
$searchString = "amazon"
WinActivate("Mozilla Firefox")
For $i = 0 To 100
Send("^" & $i)
Sleep(250)
If Not(StringInStr(WinGetTitle("[ACTIVE]"), $searchString) = 0) Then
MsgBox(0, "Done", "Found it!")
ExitLoop
EndIf
Next
Just delete the MsgBox and you're all set!
As Copas said, use FF.au3. Function _FFTabSetSelected($regex,"label") will select first tab with name matching given $regex.
Nop... The script is buggy ^^'... no need to count to 100, and there is a problem with the "send" after it:
If you send ctrl + number
=>the number can't be bigger than 9... Because ten is a number with 2 caracters, Firefox can't activate tab 10 with shortcut.
And by the way when the script is working there is a moment he release the ctrl key.. It don't send ten, but ctrl and 1 end zero ... and splash !!! It just send the number in the window.
So we need to learn to the script that the second time he's back to $i = 0 or one, all the tabs was seen, no need to continue, even if the text you're searching for was not found.
So I made my own script based on the old one:
##
AutoItSetOption("WinTitleMatchMode", 2)
$searchString = "The string you're looking for"
Local $o = 0
WinActivate("The Name of the process where you're searching")
For $i = 0 To 9
Send("^" & $i)
Sleep(250)
if ($i = 9) Then
$o += 1
EndIf
If not (StringInStr(WinGetTitle("[ACTIVE]"), $searchString) = 0) Then
MsgBox("","","Found it !") ;your action, the text was found.
ExitLoop
ElseIf ($o = 1) Then
MsgBox("","","All tab seen, not found...") ;your action, the text was not found, even after looking all title.
ExitLoop
EndIf
Next
##
I haven't touched AutoIt in years, but IIRC it will be:
setMousePos(x, y) // tab position
click("left")

Resources