【问题标题】:How can I use Autokey to grab highlighted text + url and then insert said highlighted text + url in the placeholders of a phrase?如何使用 Autokey 抓取突出显示的文本 + url,然后在短语的占位符中插入所述突出显示的文本 + url?
【发布时间】:2020-09-01 19:47:13
【问题描述】:

我正在尝试让 Autokey 像在 Windows 中为我工作的 Autohotkey 一样工作。

可以在 Autohotkey 中设置的一个非常有用的功能是分配一个键盘键来抓取突出显示的文本,然后转到 url,抓取该 url,然后将突出显示的文本和 URL 插入到预定短语中的特定位置。

用不同格式的链接创建文本非常有用。

我所描述的 Autohotkey 脚本如下所示:

insert::
clipboard =
Send, ^c
ClipWait
myText = %clipboard%
Send, !d
clipboard =
Send, ^c
ClipWait
myURL = %clipboard%
myLink = <a href="%myURL%">%myText%</a>
clipboard = %myLink%
return

有没有办法将其转换为有效的 Autokey 脚本?

【问题讨论】:

    标签: autohotkey ubuntu-18.04 autokey


    【解决方案1】:
    # assigning a keyboard key to
    # `hotkey - a key or combination of keys that, when pressed, will trigger AutoKey to do something; run a script, insert a phrase or display a menu. A hotkey can be created using any key on the keyboard (within reason), with or without one or more modifier keys. The modifier keys are Shift, Control, Alt and Super (a.k.a. Windows).`
    # [Guide](https://github.com/autokey/autokey/wiki/Beginners-Guide)
    
    import os, time
    
    # grab highlighted text
    myText = clipboard.get_selection()
    
    # then go to url
    myCmd = "/usr/bin/firefox --new-window http://www. your site .biz/"
    os.system(myCmd)
    time.sleep(0.25)
    
    # grab that url, and then
    keyboard.send_keys('<F6>')
    time.sleep(0.25)
    myURL = clipboard.get_selection()
    
    # insert the highlighted text and URL in specific places within a predetermined phrase.
    # run a window wait, then paste the texts there. Following example opens a msgbox2sec.ahk (create it first):
    myCmd = 'wine ~/.wine/drive_c/Program\ Files/AutoHotkey/AutoHotkey.exe /home/administrator/Desktop/msgbox2sec.ahk'
    os.system(myCmd)
    time.sleep(0.25)
    
    active_class = window.get_active_class()
    if not active_class == "your class name":  # for example: "autokey-gtk.Autokey-gtk":
        time.sleep(0.25)  # sleep longer
    
    myLink = "<a href = \"" + myURL + "\">" + myText + "</a>"
    # paste your link, then copy it:
    keyboard.send_keys(myLink)
    
    # select select a line:
    keyboard.send_keys('<home>')
    keyboard.send_keys("<shift>+<end>")
    
    # copy line to clipboard:
    keyboard.send_keys('<ctrl>+c')
    
    # or copy line to variable:
    c = clipboard.get_selection()
    

    【讨论】:

      猜你喜欢
      • 2020-11-09
      • 2020-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-31
      • 2012-07-01
      相关资源
      最近更新 更多