AutoHotkey Source Code:
#NoEnv
#SingleInstance Force
SetBatchLines -1
ListLines Off
SetScrollLockState,AlwaysOff
;---------------------------------------------------------------
; get_path_from_dopus.ahk
;---------------------------------------------------------------
; Scenario -
; Very often you want to paste a file path somewhere (such as in a text editor or in a file dialog). However you want to use the familiar Dopus interface to choose the file. And so you want to minimize the keystrokes required to switch to Dopus, copy the path of the file, and switch back to your original application.
;---------------------------------------------------------------
; Usage -
; 1. Press ScrollLock in any application (herein named "original application"). You will be taken to Dopus.
; 2. Select a file in Dopus and then press:
; 3a. ScrollLock - to paste the selected file path (without quotes) back into your original application.
; 3b. Shift+ScrollLock - to paste the selected file path (with quotes) back into your original application.
; 3c. Alt+ScrollLock - to cancel the operation
;---------------------------------------------------------------
; Written in AutoHotkey Classic
;---------------------------------------------------------------
mode_get_path_from_dopus := false
Return ;end of auto-execute
*ScrollLock::
If(GetKeyState("Alt", "P")) { ; Cancel get_path_from_dopus if modifier down
If(mode_get_path_from_dopus) {
WinActivate, ahk_id %get_path_from_dopus_winid%
CornerNotify_ModifyTitle("get_path_from_dopus - cancelled")
CornerNotify_ModifyMessage("")
SetTimer, CornerNotify_FadeOut_Destroy, 10
mode_get_path_from_dopus := false
} Else {
CornerNotify_ModifyTitle("get_path_from_dopus - can't cancel`, not running anyways")
CornerNotify_ModifyMessage("")
SetTimer, CornerNotify_FadeOut_Destroy, 10
}
Return
}
If(mode_get_path_from_dopus) {
Clipboard= ;empty the clipboard so ClipWait has something to wait for
Run, "C:\Program Files\GPSoftware\Directory Opus\dopusrt.exe" /cmd Clipboard SET {filepath$}
ClipWait, 0.1
If ErrorLevel {
CornerNotify_ModifyTitle("get_path_from_dopusT - error no file selected")
} Else {
file := Clipboard
clipboardrewrite := 0
If(GetKeyState("Shift", "P")) {
pastewithquotes := true
} Else {
pastewithquotes := false
}
If(pastewithquotes) { ; Add quotes
If(SubStr(file,0,1)<>"""") {
file := """" . file
clipboardrewrite := 1
}
If(SubStr(file,StrLen(file),1)<>"""") {
file := file . """"
clipboardrewrite := 1
}
If(clipboardrewrite) {
Clipboard := file
}
} Else { ; Remove quotes
If(SubStr(file,0,1)="""") {
StringTrimLeft, file, file, 1
clipboardrewrite := 1
}
If(SubStr(file,StrLen(file),1)="""") {
StringTrimRight, file, file, 1
clipboardrewrite := 1
}
If(clipboardrewrite) {
Clipboard := file
}
}
WinActivate, ahk_id %get_path_from_dopus_winid%
WinWaitActive, ahk_id %get_path_from_dopus_winid%,,2 ; wait 2 seconds
if(ErrorLevel) {
CornerNotify_ModifyTitle("get_path_from_dopus - error`, cancelling")
CornerNotify_ModifyMessage("Could not switch back to %get_path_from_dopus_process%")
SetTimer, CornerNotify_FadeOut_Destroy, 10
} Else {
Send, ^v
If(pastewithquotes) { ; Add quotes
CornerNotify_ModifyTitle("get_path_from_dopus - done`, pasted with quotes")
CornerNotify_ModifyMessage(file)
SetTimer, CornerNotify_FadeOut_Destroy, 10
} Else {
CornerNotify_ModifyTitle("get_path_from_dopus - done`, pasted")
CornerNotify_ModifyMessage(file)
SetTimer, CornerNotify_FadeOut_Destroy, 10
}
}
mode_get_path_from_dopus := false
}
} Else{
WinGet, get_path_from_dopus_winid, ID, A
WinGet, get_path_from_dopus_process, ProcessName, ahk_id %get_path_from_dopus_winid%
IfWinExist, ahk_class dopus.lister
{
WinActivate, ahk_class dopus.lister
} Else {
Run, "C:\Program Files\GPSoftware\Directory Opus\dopus.exe"
;Run, "C:\Program Files\GPSoftware\Directory Opus\dopusrt.exe" /cmd Go C:\ newtab=findexisting
Run, "C:\Program Files\GPSoftware\Directory Opus\dopusrt.exe" /cmd Go LASTACTIVELISTER
}
CornerNotify_Create("get_path_from_dopus - waiting for selection in dopus", "Window To Paste In: " . get_path_from_dopus_process . "`nScrollLock - paste selected path`nShift+ScrollLock - paste selected path with quotes`nAlt+ScrollLock - cancel")
mode_get_path_from_dopus := true
}
Return
;---------------------------------------------------------------
; CORNERNOTIFY
;---------------------------------------------------------------
CornerNotify_Create(title, message) {
global
CornerNotify_Destroy() ; make sure an old instance isn't still running or fading out
Gui,+AlwaysOnTop +ToolWindow -SysMenu -Caption +LastFound
cornernotify_hwnd := WinExist()
;WinGet, get_path_from_dopus_winid, ID, A
WinSet, ExStyle, +0x20 ; WS_EX_TRANSPARENT make the window transparent-to-mouse
WinSet, Transparent, 160
curtransp := 160
Gui,Color, 202020 ;background color
Gui,Font, c5C5CF0 s17 wbold, Arial
Gui,Add, Text, x20 y12 vcornernotify_title, %title%
Gui,Font, cF0F0F0 s15 wnorm
Gui,Add, Text, x20 y56 vcornernotify_msg, %message%
Gui,Show, NoActivate W700
WinGetPos,ix,iy,w,h, ahk_id %cornernotify_hwnd%
;x := A_ScreenWidth-w
;y := A_ScreenHeight-h
; Use MonitorWorkArea instead to get the area not taken by task bar
SysGet, Mon, MonitorWorkArea
x := MonRight - w
y := MonBottom - h
WinMove, ahk_id %cornernotify_hwnd%,,x,y
}
CornerNotify_ModifyTitle(title) {
global
GuiControl,Text,cornernotify_title, %title%
GuiControl,Move,cornernotify_title, w%w% ;resize control width to width of GUI
}
CornerNotify_ModifyMessage(message) {
global
GuiControl,Text,cornernotify_msg, %message%
GuiControl,Move,cornernotify_msg, w%w% ;resize control width to width of GUI
}
CornerNotify_Destroy() {
global
curtransp := 0
Gui, Destroy
SetTimer, CornerNotify_FadeOut_Destroy, Off
}
CornerNotify_FadeOut_Destroy:
If(curtransp > 0) {
curtransp := curtransp - 4
WinSet, Transparent, %curtransp%, ahk_id %cornernotify_hwnd%
} Else {
Gui, Destroy
SetTimer, CornerNotify_FadeOut_Destroy, Off
}
Return