Jump to content

Need help with CmdLine


Go to solution Solved by orbs,

Recommended Posts

I created a simple Browser GUI and have it set as my default browser. I found $CmdLine and which worked somewhat, with the following code whenever I click a link it'll open my compiled script and navigate to the link. 

If $CmdLine[0] > 0 Then
$oIE.navigate($CmdLine[2])
Else
$oIE.navigate("http://google.com")
EndIf

 

Problem is every time I click a link it opens a new instance of the program. How can I make it so it reuses the open instance instead of opening a new one?

Edited by ubberoinker
Link to comment
Share on other sites

hello ubberoinker, welcome to AutoIt and to the forum!

this is not a problem with $CmdLine (although i can't get why you use $CmdLine[2] instead of $CmdLine[1], but that's your business).

before you "navigate" with the IE object, you need to "attach" to existing browser instance. look at the IE UDF for _IEAttach() or _IECreate().

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

hello ubberoinker, welcome to AutoIt and to the forum!

this is not a problem with $CmdLine (although i can't get why you use $CmdLine[2] instead of $CmdLine[1], but that's your business).

before you "navigate" with the IE object, you need to "attach" to existing browser instance. look at the IE UDF for _IEAttach() or _IECreate().

 

Thank you for the welcome! Long time user of AutoIt but have been stumped by this one. I'm probably either way off or missing something obvious.

_ArrayDisplay shows me the $CmdLine array is as follows

Row|Col 0
[0]|2
[1]|-url
 

I'm not having a problem with the Navigating part, When I click a link it will open my MyBrowser.exe and navigate to the URL I clicked on. 

The problem is that every time I click a link it opens a new instance of MyBrowser.exe and navigates to the link. I don't want it to open a new instance but rather reuse the active instance and just navigate to the URL I clicked..

Edited by ubberoinker
Link to comment
Share on other sites

  • Solution

the $oIE.navigate misled me to believe you are using IE. if that is incorrect, then ignore my previous post.

you need to have your MyBrowser handle the $CmdLine differently. flow like this:

if already another instance running (use _Singleon() ), then

  just write the url to a temp text file, and exit immediately.

endif

main part: instead of:

while running

  do what you do

wend

do this:

while running

  do what you do

  if a temp text file exists, read the url from it and do what you do with it (start new tab?) and delete the temp file

wend

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

So simple yet exactly what I needed. I had played with _Singleton never thought to write a temp file. 

If _Singleton("MyBrowser", 1) = 0 Then
    FileWrite("temp.txt", $CmdLine[2])
    Exit
EndIf
If FileExists("temp.txt") Then
            $oIE.navigate(FileRead("temp.txt"))
            FileDelete("temp.txt")
        EndIf

Thank you, orbs!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...