sgp, I have been using this script extensively and loving it. Thanks again. I have a small modification request now. Is there a way to not only prevent a second program instance but to also activate the window if it is already running?
--- In [email protected], sgp acs322000 <[EMAIL PROTECTED]> wrote: > People new to powerpro often ask, "How can I run a maximized program?" > While there are many ways to accomplish this, I use the script below to > run a program the way I like it, minned, maxxed, hidden, blocking, non- > blocking, single instance, multiple instance, with optional on-screen- > display, on multi-boot systems, from a usb key, and more. > > Be sure to read all comments and examples. > Make sure to read and apply sections REQUIRED PLUGINS, and > CONFIGURATION. > > Hopefully, the script should be escape-character independent. > > Installation: > 1. Cut & paste into file runit.powerpro (or whatever name you like) in > your powerpro scripts folder > 2. All lines should start with a $ character. Join long lines. Remove > all $ characters. Done. > > Run as [EMAIL PROTECTED](...) - See EXAMPLES section > > Comments and bug fixes :-) are welcome. > > $;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > ;;;;;; > $; NAME: X > $; > $; PURPOSE: > $; run a program > $; > $; ARGUMENTS: (*=optional) > $; 1 title - show program title as On Screen Display (WinNT derivatives > only) > $; use "" for no OSD > $; 2 delay - OSD delay in ms > $; use <0 to hide program window (deprecated, see arg(7) below) > $; [EMAIL PROTECTED] blocks waiting delay ms for program to complete > $; and returns the program exit code, or 9999999 if delay exceeded > $; use 0 for wait until program exits > $; use 1 for (practically) no wait > $; 3 window caption - if window caption matches an existing window then > $; don't run the program (single instance); special cases: > $; "*" -> allow multiple instances (don't check caption) > $; "" -> generate caption as "="++file.name(arg(4)) > $; 4 program path (normally passed with escape protection as in > ?"path") > $; - absolute pathname OR > $; - relative pathname - will search for run_path in local PATH > variable > $; (initialized it below) > $; - if %envvar% included it will be expanded > $; 5* program arguments, see CAVEAT about arg(7) comspec > $; 6* initial folder > $; if "" then [EMAIL PROTECTED] will cd to the folder where arg(4) resides > $; 7* string of options, including: > $; comspec - use ComSpec envvar to start fully-resolved arg(4) with > $; /c "^"arg(4)^" arg(5)" > $; CAVEAT: since cmd.exe wants a quoted string after /c > $; escape doublt quotes in arg(5) with ^" - see examples below > $; min - minimize program window > $; max - maximize program window > $; normal - show program window (default) > $; hide OR inv - hide program window > $; > $; EXAMPLES: > $; ;basic syntax with OSD > $; [EMAIL PROTECTED]("Editor","1000", > "=notepad",?"%windir%/system32/notepad.exe") > $; ; - OR - > $; setstring x %windir/system32/notepad.exe > $; [EMAIL PROTECTED]("Editor","1000", "=notepad", x) > $; > $; ;start maximized notepad (set %windir% in local PATH variable) > $; [EMAIL PROTECTED]("",1, "*",?"notepad.exe","","","max") > $; > $; ;relative path, multiple instance: > $; [EMAIL PROTECTED]("paper", 500, "*", "IrfanView\i_view32.exe", > ?_"_++doc++?_"_) > $; > $; ;use system shell to run the document, i.e.: a pdf file > $; [EMAIL PROTECTED]("paper", -500, "*", ?"%COMSPEC%", " /c > "++?_"_++doc++?_"_) > $; > $; ;sample idiom for Context command list entry: > $; [EMAIL PROTECTED]("",1,"*","WinRar/WinRar.exe",??"!"?,file.folder(_file_)) > $; > $; ;fallback to running p2 if single instance of p1 can't run > $; ; (see also RETURN VALUE): > $; exec onerror clear > $; if ( 0 >= [EMAIL PROTECTED]("",1,caption,"path/p1.exe",args) || "" != > _LastError_ ) > $; [EMAIL PROTECTED]("",1,caption2,"path2/p2.exe",args2) > $; > $; ;run a a builtin 4nt command and exit (assumes ComSpec=cmd.exe) > $; [EMAIL PROTECTED]("",0,"*",?"4nt\4nt.exe", "beep 2000 1%=&exit","","inv comspec") > $; > $; ;resolve command-line program path then run it invisibly quoting its > $; ;arguments and waiting for completion > $; ;CAVEAT must escape quotes to cmd.exe in arg(5) > $; [EMAIL PROTECTED]("",0,"*","gema.exe", ?'-f [EMAIL PROTECTED] > ^"%TEMP%\ppro8^" > ^"%TEMP%\ppro8^"',pprofolder++?'scripts',"inv comspec") > $; ;notably above line returns 0 when all is well > $; > $; REQUIRED PLUGINS: > $; OSD.dll on-screen-display -- WinNT derivatives only > $; win.dll > $; miscplugin.dll > $; file.dll > 3.8.18 > $; > $; CONFIGURATION: > $; 1) The following GLOBAL variables must be initialized prior to > calling [EMAIL PROTECTED] > $; global gvOsdFont="Verdana Bold" ;;or whatever suits you > $; global gvOsdSize="36" ;;or whatever suits you > $; global gvOsdColor="255 000 000" ;;or whatever suits you > $; > $; OSD plugin will be called iff gvOsdFont is defined > $; hence do NOT define gvOsdFont on win98 > $; > $; 2) set local PATH variable below > $; PATH adds a lot of flexibility especially when you're running > $; powerpro on multiboot systems or from a usb key > $; > $; RETURN VALUE: > $; 0 if single instance already running > $; -1 if no valid path found > $; 9999999 if delay was exceeded > $; else file.runwait exit code which may be 0, -1 or anything else > $; you may also Exec.OnError("clear") before calling @X then check > $; if global variable _LastError_ <> "" when @X returns > $;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > ;;;;;;;; > $ > [EMAIL PROTECTED] > $; initialize local PATH variable here > $local PATH=pprofolder++"bin" \+ > $ ++"\n"++Env("bin") \+ > $ ++"\n"++Env("RootDrv")++"\\bin" \+ > $ ++"\n"++?"c:\bin" \+ > $ ++"\n"++Env("ProgramFiles") \+ > $ ++"\n"++?"c:\Program Files" \+ > $ ++"\n"++?"%windir%" \+ > $ ++"\n"++"." > $ > $if ( "" == arg(4) ) > $ quit(-1) > $ > $local run_args=arg(5) > $ > $; check for single instance > $local caption=ifelse(arg(3),arg(3),"="++file.name(arg(4))) > $if( "*" != caption && win.handlelist(caption, 1) ) > $ quit(0) > $ > $local i,j > $local s=arg(4) > $local ms=ifelse(miscplugin.is_int(arg(2)),arg(2),0) > $; resolve %envvar% > $for( i=index(s,"%");i;i=index(s,"%") ) > $ j=i+index(select(s,i+1,length(s)),"%") > $;win.debug(scriptname++"@X","["++i++","++j++"] ",select(s,i+1,j-1)) > $ s=replacechars(s,select(s,i,j),env(select(s,i+1,j-1))) > $endfor > $ > $; search in PATH > $local s1=s > $local p > $;win.debug(scriptname++"@X try to start '"++s++"'") > $for(p=1; not validpath(s) && p<=line(PATH,0); p=p+1) > $ s=line(PATH,p)++?"\"++s1 > $endfor > $if( not validpath(s) ) > $ quit(-1) > $ > $; resolve initial folder > $local folder=ifelse(arg(6),arg(6),file.folder(s)) > $;win.debug(scriptname++"@X start folder '"++folder++"'") > $ > $; show non-blocking on-screen display > $; DO NOT defined GLOBAL gvOsdFont on win9x (no OSD plugin) > $if(index(allglobals,"gvosdfont"))do > $ if( "" != arg(1)) > $ osd.show(arg(1),ifelse(ms<0,0-ms,ms), gvOsdSize, gvOsdFont,"-1", > gvOsdColor) > $endif > $ > $; process options > $; --------------- > $; command-line program? > $if(index(arg(7),"comspec"))do > $ ; ============================================================ > $ ; N.B.: user must escape all internal quotes as ^" in run_args > $ ; ============================================================ > $ run_args=?' /c "^"'++s++?'^" '++run_args++?'"' > $ s=Env("ComSpec") > $endif > $; invisible? > $local inv=0 > $if(index(arg(7),"inv") || index(arg(7),"hide") || ms<0)do > $ inv=1 > $ if(ms<0) > $ ms=0-ms > $endif > $local mode="normal" > $if(inv)do > $ mode="hide" > $elseif(index(arg(7),"max"))do > $ mode="max" > $elseif(index(arg(7),"min"))do > $ mode="min" > $endif > $ > $; run program > $win.debug(date++time,scriptname++"@X: <"++s++"> <"++run_args++"> > <"++folder++"> <"++caption++"> <"++ms++">") > $quit( file.runwait(ms,s,run_args,folder,mode) Attention: PowerPro's Web site has moved: http://www.ppro.org Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/power-pro/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
