Messages - Onesimus Prime [ switch to compact view ]

Pages: prev1 2 [3]
11
Okay, in the last section I'm trying to make the floating tooltip that continuously counts down optional.
countdown(p_count="") {
   countdown_time:=p_count
   countdown_date=16010101
   countdown_date+=%countdown_time%, s
   Loop {
      If (countdown_date >= 16010101010000){
        FormatTime, mmss, %countdown_date%, hh:mm:ss
     }else{
      FormatTime, mmss, %countdown_date%, mm:ss
      }
      ;msgbox %countdown_date%`n%hhmmss%
     ;//SB_SetText(mmss, 2)
   global floatingtimer
      ifequal, %floatingtimer%, 1, Tooltip, %mmss%, 2000,14
      Menu,Tray,Tip,Time Remaining: %mmss%
      Sleep, 1000
      countdown_date+=-1, s
      ;//IfLess, countdown_date, 16010101, break
      if (A_Index>countdown_time) {
         break
      }
   }
}

If I read the variable with
      IniRead, floatingtimer, %applicationname%.ini, Settings, floatingtimer

then why doesn't
      global floatingtimer
      ifequal, %floatingtimer%, 1, Tooltip, %mmss%, 2000,14
seem to have any effect?  The variable has the right value, but the timer tooltip still isn't showing up...

*yet another edit*
Okay, I think I got it - not because I necessarily understand what's going on, but because I looked at the .chm a bit more and kept on trying things until something worked!
applicationname=WaitAndSend
versionnumber=0.6

; by Onesimus Prime
; 2009
; For now, right-click on the tray icon to exit...

; Countdown timer code (which is the majority of what's below) from https://www.donationcoder.com/forum/index.php?topic=14895.0
; Some .ini-related code from Skrommel's templates

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#persistent

IfNotExist,%applicationname%.ini
{
  ini=[Settings]
  ini=%ini%`n
  ini=%ini%`nfloatingtimer=0
  ini=%ini%`n  `; 0 is false (no), 1 is true (yes).
  ini=%ini%`n  `; Even without a floating timer, you can mouse over the tray icon to get the current countdown.
  ini=%ini%`n
  ini=%ini%`nctimer=20
  ini=%ini%`n  `; This sets the countdown, unless it is over-ridden by launching the script with a numeric parameter.
  ini=%ini%`n  `; It is measured in minutes (and decimals are valid).
  ini=%ini%`n
  ini=%ini%`ntargetprogram=ahk_class REAPERwnd
  ini=%ini%`n  `; this is the Title or Class of the window of the target program, the program that you wish to send the below keystrokes to. 
  ini=%ini%`n  `; By default, this line includes "ahk_class REAPERwnd", summoning a window with the class matching the REAPER recording program.
  ini=%ini%`n
  ini=%ini%`nkeypresses={Space}
  ini=%ini%`n  `;the keystrokes here will be sent to the program listed above.  Your options, and the various formatting restrictions, are viewable at http://www.autohotkey.com/docs/commands/Send.htm
  ini=%ini%`n  `; By default, this line simulates a press of the Spacebar(using {Space}),  which (by Reaper's defaults) toggles "play" and "stop" (and thus can be used to stop recording!)
  ini=%ini%`n  `; You could also use {CTRLDOWN}r{CTRLUP} to send Ctrl+R, Reaper's default key combo to START recording.
  ini=%ini%`n
  ini=%ini%`nendmsg=0
  ini=%ini%`n  `; This determines whether to show a message box after sending the keypresses, or simply to exit quietly.
  ini=%ini%`n  `; 0 is false (no MsgBox), 1 is true (yes).
  FileAppend,%ini%,%applicationname%.ini
  ini=
}

IniRead, floatingtimer, %applicationname%.ini, Settings, floatingtimer

IniRead, ctimer, %applicationname%.ini, Settings, ctimer

IniRead, targetprogram, %applicationname%.ini, Settings, targetprogram
IniRead, keypresses, %applicationname%.ini, Settings, keypresses
IniRead, endmsg, %applicationname%.ini, Settings, endmsg

CoordMode, ToolTip, Screen
tt = %1%
if not tt
   tt = %ctimer%
;tt = 120
time := Convert_Milliseconds(tt)
Sec := (tt * 60)

SetTimer, nMessage, %time%
countdown(Sec)
return

nMessage:
SetTimer, nMessage, Off

WinActivate %targetprogram%
WinWaitActive %targetprogram%
send %keypresses%
sleep 1000
ifequal, endmsg, 1, MsgBox Your keypresses have been sent to the requested program.
;Gui, +MinimizeBox
;GUi, -sysmenu
;gui, +toolwindow
;Gui, Add, Button, w130, DONE - hit 'O' for OK
;Gui, Show, x1 y1, %applicationname% %versionnumber%

;KeyWait, o, D
;Tooltip ,, 2, 980
;Gui Destroy

exitapp


Convert_MilliSeconds(time,MS = 1000,M = 60)
{
   return MS*M*time
}

countdown(p_count="") {
   countdown_time:=p_count
   countdown_date=16010101
   countdown_date+=%countdown_time%, s
   Loop {
      If (countdown_date >= 16010101010000){
        FormatTime, mmss, %countdown_date%, hh:mm:ss
     }else{
      FormatTime, mmss, %countdown_date%, mm:ss
      }
      ;msgbox %countdown_date%`n%hhmmss%
     ;//SB_SetText(mmss, 2)
      global floatingtimer
      ifequal, floatingtimer, 1, Tooltip, %mmss%, 2000,14
      Menu,Tray,Tip,Time Remaining: %mmss%
      Sleep, 1000
      countdown_date+=-1, s
      ;//IfLess, countdown_date, 16010101, break
      if (A_Index>countdown_time) {
         break
      }
   }
}

12
I so should have been sleeping... *chagrined*
Okay, I first wrote a simple one like what you described, skwire--about 4 lines is all it takes, I didn't realize it'd be so simple!  But then I couldn't leave well enough alone...  I did a forum search, grabbing the countdown timer code from https://www.donationcoder.com/forum/index.php?topic=14895.0 and integrating the use of an .ini file (thanks to Skrommel's stuff), and the below is the (seemingly working) monstrosity that resulted  ;D :
applicationname=WaitAndSend
versionnumber=0.5

; by Onesimus Prime
; 2009
; For now, right-click on the tray icon to exit...

; Countdown timer code (which is the majority of what's below) from

https://www.donationcoder.com/forum/index.php?topic=14895.0
; Some .ini-related code from Skrommel's templates

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey

releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and

reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#persistent

IfNotExist,%applicationname%.ini
{
  ini=[Settings]
  ini=%ini%`n
  ini=%ini%`nctimer=20
  ini=%ini%`n  `; This sets the countdown, unless it is over-ridden by

launching the script with a numeric parameter.
  ini=%ini%`n  `; It is measured in minutes (and decimals are valid).
  ini=%ini%`n
  ini=%ini%`ntargetprogram=ahk_class REAPERwnd
  ini=%ini%`n  `; this is the Title or Class of the window of the target

program, the program that you wish to send the below keystrokes to. 
  ini=%ini%`n  `; By default, this line includes "ahk_class REAPERwnd",

summoning a window with the class matching the REAPER recording program.
  ini=%ini%`n
  ini=%ini%`nkeypresses={Space}
  ini=%ini%`n  `;the keystrokes here will be sent to the program listed above.

 Your options, and the various formatting restrictions, are viewable at

http://www.autohotkey.com/docs/commands/Send.htm
  ini=%ini%`n  `; By default, this line simulates a press of the Spacebar

(using {Space}),  which (by Reaper's defaults) toggles "play" and "stop" (and

thus can be used to stop recording!)
  ini=%ini%`n  `; You could also use {CTRLDOWN}r{CTRLUP} to send Ctrl+R,

Reaper's default key combo to START recording.
  FileAppend,%ini%,%applicationname%.ini
  ini=
}

IniRead, ctimer, %applicationname%.ini, Settings, ctimer

IniRead, targetprogram, %applicationname%.ini, Settings, targetprogram
IniRead, keypresses, %applicationname%.ini, Settings, keypresses

CoordMode, ToolTip, Screen
tt = %1%
if not tt
   tt = %ctimer%
;tt = 120
time := Convert_Milliseconds(tt)
Sec := (tt * 60)

SetTimer, nMessage, %time%
countdown(Sec)
return

nMessage:
SetTimer, nMessage, Off

WinActivate %targetprogram%
WinWaitActive %targetprogram%
send %keypresses%
sleep 1000
; MsgBox Your keypresses have been sent to the requested program.
Gui, +MinimizeBox
GUi, -sysmenu
gui, +toolwindow
Gui, Add, Button, w130, DONE - hit 'O' for OK
Gui, Show, x1 y1, %applicationname% %versionnumber%

KeyWait, o, D
Tooltip ,, 2, 980
Gui Destroy
exitapp


Convert_MilliSeconds(time,MS = 1000,M = 60)
{
   return MS*M*time
}

countdown(p_count="") {
   countdown_time:=p_count
   countdown_date=16010101
   countdown_date+=%countdown_time%, s
   Loop {
      If (countdown_date >= 16010101010000){
        FormatTime, mmss, %countdown_date%, hh:mm:ss
     }else{
      FormatTime, mmss, %countdown_date%, mm:ss
      }
      ;msgbox %countdown_date%`n%hhmmss%
     ;//SB_SetText(mmss, 2)
      Tooltip, %mmss%, 2000,14
      Menu,Tray,Tip,Time Remaining: %mmss%
      Sleep, 1000
      countdown_date+=-1, s
      ;//IfLess, countdown_date, 16010101, break
      if (A_Index>countdown_time) {
         break
      }
   }
}

You were right about a "locked" computer--it seems to wait until the computer is unlocked before executing the after-timer stuff.  One workaround, I guess, might be to use KidSafe Portable to "lock" the computer instead.  "Windows + L can cut off some processes (e.g. it always pauses my virus scanner and media player, and turns off my Internet); KidSafe doesn’t do that" (according to a quote here).

13
I forgot about "WinActivate and WinWaitActive" - I'll look into those.  I think I've used the other commands before. Thanks!

Oh, I forgot--will this still work if the computer's "locked"?

14
What I was kind of hoping for/envisioning was a portable, cross-browser (or at least IE-compatible) version of the CopyAllUrls extension for FireFox.  That extension, which is fairly flexible, can save the URLs and titles of open webpages across multiple tabs and even going back through a tab's history!  The user also defines the format for the output.

I downloaded the source for Skrommel's UrlHistory and tweaked it a bit as a first step toward this.  Right now, it uses the hard-coded shortcut keys Ctrl+Shift+C to copy the current IE tab's URL and title, Ctrl+Shift+V to paste all of these that have been copied (and empty the 'database' or whatever), Ctrl+Shift+E to empty the 'database' without pasting, and Ctrl+Shift+Q to quit.

Let me say that I don't really know AHK, so any and all alterations may be somewhat hack-ish, there's probably some now-unnecessary code, etc.  And yes, I found the thread with a similar request, but 1) I'm posting code  :), and 2) more importantly, I think my goals for this program and my implementation are slightly different...
;UrlCopy.ahk
;version 1.0.3
; changes: no longer puts URLs in tray menu
; grabs webpage address and name from current IE tab
;Skrommel @ 2006
;modified by Onesimus Prime


#SingleInstance,Force
#Persistent

applicationname=UrlCopy

changed=0
Gosub,READINI
Gosub,TRAYMENU
Return

^+c::Send, {ALTDOWN}d{ALTUP}{CTRLDOWN}c{CTRLUP}
^+e::
  ; FileRecycle, %applicationname%.htm
  FileDelete, %applicationname%.htm
  FileAppend,,%applicationname%.htm
  Gosub,TRAYMENU
  Return
^+v::
  clipboard =   ;Empty the clipboard
  FileRead,clipboard,%applicationname%.htm
  Send,{CTRLDOWN}v{CTRLUP}
  clipboard =   ;Empty the clipboard
  FileDelete, %applicationname%.htm
  Return
^+q::
  FileDelete, %applicationname%.htm
  ExitApp
  Return

; IfWinActive,ahk_class IEFrame
OnClipboardChange:
If watch<>1
  Return
If A_EventInfo<>1
  Return
If changed=1
  Return
urls=
end=
Loop
{
  start=999999
  StringGetPos,pos1,clipboard,http,,%end%
  StringGetPos,pos2,clipboard,www,,%end%
  StringGetPos,pos3,clipboard,ftp,,%end%

  If (pos1>-1)
    start:=pos1
  If (pos2<start And pos2>-1)
    start:=pos2
  If (pos3<start And pos3>-1)
    start:=pos3
  If start=999999
    Break

  StringGetPos,pos4,clipboard,%A_Space%,,%start%
  StringGetPos,pos5,clipboard,%A_Tab%,,%start%
  StringGetPos,pos6,clipboard,`n,,%start%

  end:=start
  If (pos4>-1)
    end:=pos4
  If (pos5<end And pos5>-1)
    end:=pos5
  If (pos6<end And pos6>-1)
    end:=pos6
  If (end=start)
    StringLen,end,clipboard

  length:=end-start
  StringMid,url,clipboard,%start%,%length%
  If url<>
  {
    WinGetActiveTitle,title
    ; InputBox,title,%applicationname%,Please enter comment for`n%url%,,400,150,,,,,%title%
    ; If ErrorLevel=0
      StringReplace,TitleMinusIE,title, - Windows Internet Explorer
      AutoTrim Off
      urls=%A_Space%%A_Space%%A_Space%%urls%%url%  - %TitleMinusIE%`n
  }
}
If urls<>
{
  FileAppend,%urls%,%applicationname%.htm
}
GOSUB,TRAYMENU
Return



TRAYMENU:
Menu,Tray,DeleteAll
Menu,Tray,NoStandard
Menu,Tray,Add,%applicationname%,ADD
Menu,Tray,Default,%applicationname%
Menu,Tray,Add,
Menu,Tray,Add,&Add Url...,ADD
Menu,Tray,Add,&Edit Urls...,EDIT
Menu,Tray,Add,
Menu,Tray,Add,&Settings...,SETTINGS
Menu,Tray,Add,A&bout...,ABOUT
Menu,Tray,Add,E&xit,EXIT
Menu,Tray,Tip,%applicationname%
Return


EDIT:
RunWait,Notepad.exe %applicationname%.htm,,UseErrorLevel
Gosub,TRAYMENU
Return


ADD:
InputBox,url,%applicationname%,Please enter web address,,400,150,,,,,http://
If ErrorLevel<>0
  Return
InputBox,comment,%applicationname%,Please enter comment for`n%url%,,400,150
If ErrorLevel<>0
  Return
FileAppend,%url% - %comment%`n,%applicationname%.htm
Gosub,TRAYMENU
Return


OPEN:
StringSplit,url_,A_ThisMenuItem,%A_Space%-

If run=1
{
  IfNotInString,url_1,http
  IfNotInString,url_1,ftp
  url=http://%url_1%
  Run,%url_1%,,UseErrorLevel
}
If paste=1
{
  changed=1
  clipboard=%url_1%
}
Sleep,2000
changed=0
Return


SETTINGS:
Gosub,READINI
RunWait,Notepad.exe %applicationname%.ini
Gosub,READINI
Return


READINI:
IfNotExist,%applicationname%.ini
{
  ini=`;[Settings]
  ini=%ini%`n`;lines=20   `;number of lines to show in the tray menu
  ini=%ini%`n`;watch=1    `;1=yes 0=no  watch the clipboard for urls
  ini=%ini%`n`;run=1      `;1=yes 0=no  open the clicked url in the default browser
  ini=%ini%`n`;paste=1    `;1=yes 0=no  paste the clicked url to the clipboard
  ini=%ini%`n`;comment=1  `;1=yes 0=no  add a comment to the copied url
  ini=%ini%`n
  ini=%ini%`n[Settings]
  ini=%ini%`nlines=20
  ini=%ini%`nwatch=1
  ini=%ini%`nrun=1
  ini=%ini%`npaste=1
  ini=%ini%`ncomment=1
  FileAppend,%ini%,%applicationname%.ini
  ini=
}
IniRead,lines,%applicationname%.ini,Settings,lines
IniRead,watch,%applicationname%.ini,Settings,watch
IniRead,run,%applicationname%.ini,Settings,run
IniRead,paste,%applicationname%.ini,Settings,paste
IniRead,comment,%applicationname%.ini,Settings,comment
Return


ABOUT:
Gui,99:Destroy
Gui,99:Margin,20,20
Gui,99:Add,Picture,xm Icon1,%applicationname%.exe
Gui,99:Font,Bold
Gui,99:Add,Text,x+10 yp+10,%applicationname% v1.0.1
Gui,99:Font
Gui,99:Add,Text,y+10,Copies web page addresses and titles from Internet Explorer
; Gui,99:Add,Text,y+5,- Change settings using Settings in the tray menu
Gui,99:Add,Text,y+5,- Doubleclick the tray icon to add a url and comment manually

Gui,99:Add,Text,y+10,
Gui,99:Add,Picture,xm y+20 Icon5,%applicationname%.exe
Gui,99:Font,Bold
Gui,99:Add,Text,x+10 yp+10,1 Hour Software by Skrommel
Gui,99:Font
Gui,99:Add,Text,y+10,UrlCopy is based on Skrommel's UrlHistory, available at
Gui,99:Font,CBlue Underline
Gui,99:Add,Text,y+5 G1HOURSOFTWARE,www.1HourSoftware.com
Gui,99:Font

Gui,99:Add,Picture,xm y+20 Icon7,%applicationname%.exe
Gui,99:Font,Bold
Gui,99:Add,Text,x+10 yp+10,DonationCoder
Gui,99:Font
Gui,99:Add,Text,y+10,Please support the contributors at
Gui,99:Font,CBlue Underline
Gui,99:Add,Text,y+5 GDONATIONCODER,www.DonationCoder.com
Gui,99:Font

Gui,99:Add,Picture,xm y+20 Icon6,%applicationname%.exe
Gui,99:Font,Bold
Gui,99:Add,Text,x+10 yp+10,AutoHotkey
Gui,99:Font
Gui,99:Add,Text,y+10,This tool was made using the powerful
Gui,99:Font,CBlue Underline
Gui,99:Add,Text,y+5 GAUTOHOTKEY,www.AutoHotkey.com
Gui,99:Font

Gui,99:Show,,%applicationname% About
hCurs:=DllCall("LoadCursor","UInt",NULL,"Int",32649,"UInt") ;IDC_HAND
OnMessage(0x200,"WM_MOUSEMOVE")
Return

1HOURSOFTWARE:
  Run,http://www.1hoursoftware.com,,UseErrorLevel
Return

DONATIONCODER:
  Run,https://www.donationcoder.com,,UseErrorLevel
Return

AUTOHOTKEY:
  Run,http://www.autohotkey.com,,UseErrorLevel
Return

99GuiClose:
  Gui,99:Destroy
  OnMessage(0x200,"")
  DllCall("DestroyCursor","Uint",hCur)
Return

WM_MOUSEMOVE(wParam,lParam)
{
  Global hCurs
  MouseGetPos,,,,ctrl
  If ctrl in Static9,Static13,Static17
    DllCall("SetCursor","UInt",hCurs)
  Return
}
Return


EXIT:
ExitApp

Any ideas thus far?  Does anyone more knowledgeable and skilled (perhaps even Skrommel himself) want to "take this and run with it," bringing it closer to my original hopes of CopyAllUrls-like functionality?


*edit*
I did a lot of the modifications on this a while ago, before starting a "changelog."  But here's a relatively recent and very incomplete one:

0.1.3
Removed Skrommel's code that puts the URLs in the tray menu (below).  I hope this will fix the error message on extremely long URLs/titles, such as with Google Image results.
urls=
Loop,Read,%applicationname%.htm
{
  urls=%A_LoopReadLine%`n%urls%
  If (A_Index>lines)
    Break
}
Loop,Parse,urls,`n
{
  Menu,Tray,Add,%A_LoopField%,OPEN
}

0.1.2
Added a line to clear (erase) the HTML file of copied URLs when pasting!  Usually I was doing paste, clear - so why not combine the steps?  (Though this would be better as a user-defineable option, as would the shortcut keys...)


15
I may not know the depth of what I'm asking for, but here goes...

Would it be possible to have a program that, at a customizable system time or in 'x' mintes/seconds, makes sure that program 'y' is focused and sends it user-definable keystrokes?  And it'd be nice if this were "portable," not writing outside its own directory.

The situation prompting this request...
I'm recording a professor's lectures, and sometimes have to ditch class and leave the computer recording when he goes over-time.  After my next class, I come back and stop the recording--but this means that there's well over an hour of silence at the end of the recorded file!  And, even compressed, that takes up HD space, sometimes more than I have.  
So I was thinking it would be nice to have a program do something like, in my case, "in 10 minutes, switch to Reaper (going off of window titles?) and send key combination Ctrl+R (or whatever it is) to stop recording." (I guess by default, space is stop, but the possibility for key combinations--even a few combos in succession, maybe with "sleep" pauses in between, would maximize flexibility for other possible uses)

If anyone can help with this without too much trouble (or knows of something similar and portable), it'd be much appreciated!  Thanks!

*edit* - it's got a name now!

Pages: prev1 2 [3]
Go to full version