1
votes

I'm trying to get Autokey to work like Autohotkey worked for me in Windows.

One very useful function that was possible to set up in Autohotkey was assigning a keyboard key to grab highlighted text, then go to url, grab that url, and then insert the highlighted text and URL in specific places within a predetermined phrase.

It was extremely useful to create text with links in different formats.

The Autohotkey script for what I'm describing looked something like this:

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

Is there a way to translate that into a working Autokey script?

1

1 Answers

1
votes
# 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()