I'm looking for a way in AutoHotkey to put the currently visited url in a variable.
The goal of this AHK is to trace what I've been doing during the day to log my hours better. I have another system which I use to clock my work, but sometimes I forget to use it when I get side-tracked.
loop
{
; Get current Window ID & Name
WinGet, active_id, ID, A
WinGet, process_name, ProcessName, A
; Only do anything if any other windows was activated
if(active_id = PrevActiveId)
{
; Do nothing
}
else
{
; Format the time-stamp.
current=%A_DD%/%A_MM%/%A_YYYY%, %A_Hour%:%A_Min%
; Write this data to the log.txt file.
fileappend, %current% - %process_name%`n, log.txt
; Get the URL if process_name = "chrome.exe"
if(process_name = "chrome.exe")
{
; Put URL in log file
; fileappend, %current% - %current_url%`n, log.txt
}
}
PrevActiveId = %active_id%
Sleep, 100
}
All browsers that I've used support Alt+D to focus and select the url. Here are my AHK scripts that duplicates the current tab in Google Chrome, Firefox, and Internet Explorer by pressing Ctrl+Shift+D..
#IfWinActive ahk_class MozillaUIWindowClass ; Mozilla Firefox 3.x
^+d::GenericDuplicateTab() ; (Control+Shift+D)
#IfWinActive
#IfWinActive ahk_class MozillaWindowClass ; Firefox 4, 5, 6, 7, 8+ (?)
^+d::GenericDuplicateTab() ; (Control+Shift+D)
#IfWinActive
#IfWinActive ahk_class Chrome_WidgetWin_1 ; Chromium and Chrome 19+
^+d::GenericDuplicateTab() ; (Control+Shift+D)
#IfWinActive
#IfWinActive ahk_class Chrome_WidgetWin_1 ; Chrome 18 and less
^+d::GenericDuplicateTab() ; (Control+Shift+D)
#IfWinActive
#IfWinActive ahk_class IEFrame
^+d::InternetExplorerDuplicateTab() ; (Control+Shift+D)
#IfWinActive
GenericDuplicateTab()
{
; Wait for both Control and Shift to be released.
KeyWait Control
KeyWait Shift
BackupClipbrd := Clipboard
Sleep 50
Send !d ; Select the url textbox
Sleep 150
Send ^x ; Copy the url
ClipWait 0.1
If ERRORLEVEL
{
Clipboard := BackupClipbrd
Return
}
Send ^t ; Open a new tab
Sleep 50
Send ^v ; Paste the url into the new tab's url textbox
Sleep 50
Send {Enter}
Clipboard := BackupClipbrd
}
InternetExplorerDuplicateTab()
{
; Wait for both Control and Shift to be released.
KeyWait Control
KeyWait Shift
Send ^k ; Call IE's shortcut to duplicate tab (Control+K)
Sleep 100
Send ^{TAB} ; Switch to that tab
}
For Chrome, get the text of the control Chrome_OmniboxView1, which is the omnibox (as for the current version of Chrome, 21.0.1180.83).
This code puts the content of the omnibox into the variable omniboxContents:
ControlGetText omniboxContents, Chrome_OmniboxView1, Chrome
Note that omniboxContents doesn't necessarily contain a correct URL, because "http://" is left out if the URL starts with "http://". So instead of "http://www.google.com" you will get "www.google.com", which strictly speaking isn't a correct URL. This is simply because Chrome shows the address that way in the Omnibox. You will have add extra code to get a correct URL from the contents of the omnibox.
Or you can use F6.
Most of the browsers get to address bar and select entire URL for you when press F6.
Then its just matter of copy-paste.
For newer Firefox versions, its Ctrl+L though.
For this, you can check window title.
A clean way to do this:
GroupAdd, WebBrowsers, ahk_class MozillaWindowClass
GroupAdd, WebBrowsers, ahk_class IEFrame
GroupAdd, WebBrowsers, ahk_class Chrome_WidgetWin_0
GroupAdd, WebBrowsers, ahk_class Chrome_WidgetWin_1
GroupAdd, WebBrowsers, ahk_class OperaWindowClass
GroupAdd, WebBrowsers, ahk_class {1C03B488-D53B-4a81-97F8-754559640193}
; etc.
#IfWinActive, ahk_group WebBrowsers
{
^+d::
; [Instructions...]
return
}#If
It is also possible to do it without relying on the clipboard, by directly inspecting the actual components which make up the browser window. More info: http://www.autohotkey.com/board/topic/111114-get-the-url-of-the-current-active-browser-tab/. This method much more effective, but relies on using OS APIs.
You can use the Alt+D shortcut to activate address bar and then copy the url using Ctrl+C shortcut
F1::
{
Send, !d
Sleep 50
Send, ^c
Sleep 50
Return
}
Related
I have this problem every time I use a ( or any of " ' { [. I have plugin that automatically closes it by corresponding ) " ' } ] but I am stuck inside the parenthesis or inside double quotes
String s="I completed typing the string but my cursor is stuck right here |";
I want exit the enclosure by pressing something for all. In VScode I can press the same symbol if my cursor is right behind it and it gets past the enclosure or by pressing tab
I can exit the enclosure without reaching for right arrow
If your plugin is 'jiangmiao/auto-pairs' it has a variable called g:AutoPairsShortcutJump you can set as you want or use the default tha is Altn.
" Jump outside '"({
" -> default Alt-n
if !exists('g:AutoPairsShortcutJump')
let g:AutoPairsShortcutJump = '<A-l>'
endif
Note: If your cursor it close to the end atom you can just repeat that one to jump outside. For example:
Let's supose the character `|' represents your cursor
(|)
Just press closing parenthesis will jump outside
I am facing a problem with backspace in bash when used in restricted mode. I have already googled through lots of things, nothing worked or matching scenario am facing.
On pressing backspace, cursor is moving forward by one white space, but internally actually it's deleting the previous letter, i.e. on pressing "enter" it actually works but not visible on screen.
Example: command "ls backspace backspace", don't list anything (as expected) but on screen ls is visible after 2 backspaces and extra 2 white spaces are appended.
Looking forward for helpful suggestions. :)
Thanks in advance !! :)
Below is the piece of patch i used to chroot my bash.
Please have look and notify me if something is wrong here.
file: shell.c: ## -384,6 +387,30 ##
+ if (getcwd(pwd,sizeof(pwd)) != pwd )
+ {
+ return -1;
+ }
+ /* chroot to mount point path */
+ if( !(chroot(chroot_dir)))
+ {
+ seteuid(getuid());
+ setegid(getgid());
+ /* On successful to chroot env invoke bash prompt */
+ if(! chdir(pwd))
+ {
+ if(execlp("/rbin/bash","/rbin/bash","--restricted",NULL))
+ {
+ }
+ }
+ else
+ {
+ chdir("/");
+ if(execlp("/rbin/bash","/rbin/bash","--restricted",NULL))
+ {
+ }
+ }
+ }
Try using Backspace with Shift key, It should work.
If pressing backspace is printing a character, then you can use stty to change terminal settings like this: stty erase backspace_character where backspace_character is the character you get while pressing backspace.
you can use emacs command
for shell terminal you can hit command as below
set -o emacs
for vi editor you can hit command as below
set -o vi
I am trying to make a complete BASH menu with submenus via select opt in.
The problem : When I go to a submenu then come back to the initial menu, it do not show options.
----------------------------------------------
Greenwatch's Kiosk debug menu
----------------------------------------------
1) Keyboard Layout, 5) Configure Kiosk's password,
2) Timezone configuration, 6) Set Proxy,
3) -, 7) Remove Proxy
4) Launch Kiosk anyway,
Enter your choice (mainmenu), press 0 to reboot: 1
1) Azerty layout (BE)
2) Querty layout (US)
3) Cancel
Enter your choice (submenu): 1
AZERTY Keyboard configured
Enter your choice (mainmenu), press 0 to reboot:
This is the code(simplified -with only one submenu- )
choose_keyboard() {
show_title "Choose your keyboard layout"
clear;
select opt in "Azerty layout (BE)" "Querty layout (US)" "Cancel"; do
case "$REPLY" in
1 ) loadkeys be-latin1; echo "AZERTY Keyboard configured"; break;;
2 ) loadkeys us; echo "QWERTY Keyboard configured"; break;;
3 ) echo "Canceled"; break;;
777 ) break;;
*) echo "This is not a valid option, retry";;
esac
done
}
main_menu() {
show_title "$title"
select opt in "${options[#]}"; do
case "$REPLY" in
0 ) show_title "See you as late as possible!"; sudo systemctl reboot;;
1 ) choose_keyboard;;
2 ) choose_timezone;;
3 ) lauch_kiosk;;
4 ) choose_password;;
5 ) choose_ipconfig;;
6 ) choose_proxy;;
7 ) choose_testlab;;
777 ) break;;
*) echo "This is not a valid option, retry";;
esac
done
}
main_menu
How could I force select to display the menu?
NOTE: If I call main_menu into the choose_keyboard function, I will certainly obtain a stackoverflow error!
When you break from the inner select, you re-enter the top (main menu) select - as you have discovered, the menu isn't displayed because you don't re-execute the commands at the beginning of the function. Instead, you can break out of the inner and outer selects at once, and have the main menu in a loop so that it gets called again, ie:
1 ) loadkeys be-latin1; echo "AZERTY Keyboard configured"; break 2;;
break 2 will break out of a select nested inside another, break 3 will break out of an additional level of nesting, etc. Then instead of just calling main_menu at the bottom, do something like:
while :; do main_menu; done
This is an infinite loop which will call main_menu whenever you break out of the main menu select command. You may not want it to be infinite, you can always test against a variable or something there.
I'm trying to create a script so that during a task my keyboard/mouse is restricted from use aswell as whilst waiting for something what doesn't have a trigger/way of detecting if it's done I need it to stop me or anyone from moving the mouse/typing for at least 40 seconds.
Would this be possible to do in autoit and if so does anyone know how I can acheive this?
thanks GTPE
You're looking for BlockInput() which allows you to block keyboard and mouse from doing anything, the overriding command is: CTRL + ALT + DELETE
Basically just put BlockInput(1) at the start which will stop all keyboard/mouse from functioning
Then at the end put BlockInput(0) which releases control and allows you to do what you want.
60 Second BlockInput
BlockInput(1)
$timer = 60
For $i = 1 To $timer Step +1
Sleep(1000)
$Coords = MouseGetPos()
ConsoleWrite($timer - $i & " seconds Remaining" & #CRLF)
TrayTip("Keyboard & Mouse Frozen", $timer - $i & " seconds Remaining", 1)
ToolTip($timer - $i & " seconds Remaining", $Coords[0], $Coords[1], "Keyboard & Mouse Frozen")
Next
BlockInput(0)
I added notifications using ConsoleWrite, TrayTip and ToolTip just so that it doesn't freeze and confuse you.
Psst: This bit of code is fantastic for when you want to clean a keyboard without unplugging it or turning the computer off :P
In vim, you can check if a file is open in the current buffer with bufexists. For a short filename (not full path), you can check if it's open using bufexists(bufname('filename')).
Is there any way to check if a file is open in a tab?
My closest workaround is to do something like:
:tabdo if bufnr(bufname('filename')) in tabpagebuflist(): echo "Yes"
However, that's sort of pythonic pseudocode... I'm not sure how to get that to work in vim. My goal is for an external applescript to check if a file is already open and if so go to a line in that file.
Ideally, I'd like to be able to search through different GUI windows too, but I've gathered (e.g. Open vim tab in new (GUI) window?) that working with different GUI windows is very challenging / impossible in VIM.
My impatience and good documentation got the better of me... here's the solution (greatly aided by Check if current tab is empty in vim and Open vim tab in new (GUI) window?). The source is at https://github.com/keflavich/macvim-skim
function! WhichTab(filename)
" Try to determine whether file is open in any tab.
" Return number of tab it's open in
let buffername = bufname(a:filename)
if buffername == ""
return 0
endif
let buffernumber = bufnr(buffername)
" tabdo will loop through pages and leave you on the last one;
" this is to make sure we don't leave the current page
let currenttab = tabpagenr()
let tab_arr = []
tabdo let tab_arr += tabpagebuflist()
" return to current page
exec "tabnext ".currenttab
" Start checking tab numbers for matches
let i = 0
for tnum in tab_arr
let i += 1
echo "tnum: ".tnum." buff: ".buffernumber." i: ".i
if tnum == buffernumber
return i
endif
endfor
endfunction
function! WhichWindow(filename)
" Try to determine whether the file is open in any GVIM *window*
let serverlist = split(serverlist(),"\n")
"let currentserver = ????
for server in serverlist
let remotetabnum = remote_expr(server,
\"WhichTab('".a:filename."')")
if remotetabnum != 0
return server
endif
endfor
endfunction
then use like so:
exec "tabnext ".WhichTab('my_filename')
echo remote_foreground( WhichWindow('my_filename') )
or, from the command line, here's a script to go to a particular line of a file using WhichTab:
#!/bin/bash
file="$1"
line="$2"
for server in `mvim --serverlist`
do
foundfile=`mvim --servername $server --remote-expr "WhichTab('$file')"`
if [[ $foundfile > 0 ]]
then
mvim --servername $server --remote-expr "foreground()"
mvim --servername $server --remote-send ":exec \"tabnext $foundfile\" <CR>"
mvim --servername $server --remote-send ":$line <CR>"
fi
done
I'd reply to keflavich, but I can't yet...
I was working on a similar problem where I wanted to mimic the behavior of gvim --remote-tab-silent when opening files inside of gvim. I found this WhichTab script of yours, but ran into problems when there is more than one window open in any given tab. If you split windows inside of tabs, then you will have more than one buffer returned by tabpagebuflist(), so your method of using the buffer number's position in the List doesn't work. Here's my solution that accounts for that possibility.
" Note: returns a list of tabnos where the buf is found or 0 for none.
" tabnos start at 1, so 0 is always invalid
function! WhichTabNo(bufNo)
let tabNos = []
for tabNo in range(1, tabpagenr("$"))
for bufInTab in tabpagebuflist(tabNo)
if (bufInTab == a:bufNo)
call add(tabNos, tabNo)
endif
endfor
endfor
let numBufsFound = len(tabNos)
return (numBufsFound == 0) ? 0 : tabNos
endfunction
I think I can just return tabNos which will be an empty list that gets evaluated as a scalar 0, but I just learned vimscript and am not that comfortable with the particulars of its dynamic typing behavior yet, so I'm leaving it like that for now.