(MY) MAJOR BREAKTHROUGH: now, you can use Opera Mini as the system-level Web browser!

Search This thread

badbob001

Senior Member
Mar 28, 2005
320
17
badbob001, I screwed up :) this affects users with over 9 java apps installed. Here's the line code that needs to check for end of line or comma rather than taking the next three chars.

prog_id = SubStr( prog_line , Find(line,"=") , 3 )

I changed it to this...

prog_id = SubStr( prog_line , Find(prog_line,"=")+1 , (Find(prog_line,"_")+1)-(Find(prog_line,"=")+1) )

Good catch. I guess you have been installing and uninstalling opera a lot in your testing.
 

badbob001

Senior Member
Mar 28, 2005
320
17
After catching up on this thread, I just upgraded to OM 4.1 and am trying the updated scripts. (Thanks all).

I'm running a cooked ROM that has Esmertec Jbed, but I don't have this registry item so script failing so am a bit confused why not. Any information you can share with me? I'm a midlet NOOB. :eek:

Here's the snip from the script that is failing - and I don't have a jarfile key under HKCR.

Code:
ReadFile(RegRead("HKCR","jarfile\Shell\Save\Save Location","") & "\selector.utf")

Most of the JVMs I've seen will have that registry entry. Perhaps the designer of your rom left it out by mistake. Since you didn't say you got an error for 'HKCR\jarfile\Shell\Open\Command', I'll assume you have that entry. If that is so, check out my new version below, which does more requirements checking and may resolve your issue.
 
Last edited:

JZ SmartMort

Senior Member
Mar 24, 2008
784
16
Burbank
Good catch. I guess you have been installing and uninstalling opera a lot in your testing.

I wish it was my testing, I'm much better at deleting JBed and starting over :)

It was the guy from the BrightHand post who had issues sent me his selector.utf file, I realized why he kept getting "can't find s10 app" in Jbed rather than s10_ ---Underscore made all the difference :)
 
Last edited:

badbob001

Senior Member
Mar 28, 2005
320
17
New version (again).

I've added JZ's update where s10_ and up are supported.

Resolved a bug in my last version where if OM is already running and you have the script start OM with no url specified, it may complain that it couldn't detect if OM started correctly. This is because I didn't want to kill an existing OM and lose the current page if no new url is specified. But by not killing jbed.exe first, OM may not be in a known state for the color check to work correctly. So I had to decide when to kill jbed and when to check if jbed started correctly.

I want my script to be a general launcher for OM so it can be used in shortcuts. I would expect people to use the shortcut to start OM and use the shortcut again to get back to the existing running OM, which meant it would not be nice if I killed OM every time the shortcut is used and lose the user's current page. So I've decided upon the following logic:

1. If script is run with an url specified, then jbed will be killed first since I need a known state to correctly enter the url.

2. If no url is specified and jbed is already running, then I assume the script started OM correctly before and so there is no need to check if OM starts correctly in this instance. Jbed is not killed so the user does not lose the current page.

3. If no url is specified and jbed is not running, then I can safely start OM and do my color check. This covers the possibility that this is the first time the script is run or a setting re-detect just ran, so I should check if OM starts correctly.

Also added a lot of requirements checks and some alternative checks for non-standard jbed installations.
Specifically, if the device has the key 'HKCR\jarfile\Shell\Open\Command' (for finding jbed.exe) but not the key 'jarfile\Shell\Save\Save Location' (for finding selector.utf), I will try to use the value from 'HKCR\jarfile\Shell\Open\Command' to find selector.utf.

FYI: The system to detect if OM started correctly doesn't work if OM is in landscape mode. Sorry.

Code:
wait_time_for_opera = 10
 #default = 10 seconds

wait_time_for_address = 2
 #default = 2 seconds

wait_time_between_keys = 100
 #default = 100 milliseconds

operaRed =  rgb(107, 12, 8)
operaBlue = rgb(247, 243, 247)
checkPixelx = 0
checkPixely = 0
ini_file = SystemPath("ScriptPath") &"\"& SystemPath("ScriptName") &".ini"

if (substr(url,1,1) eq " ")
	url = substr(url,2)
EndIf

If (url ne "")
	If (Find("file://", ToLower(url)))
		Run("\Windows\iexplore.exe", url)
		exit
	EndIf
EndIf

main_loop_done = False
while(main_loop_done eq False)
	ini_ok = False
	call validate_ini
	if ( (ini_ok eq True) AND (main_loop_done eq False) )
		call startOM
	EndIf
	if ( (ini_ok eq False) AND (main_loop_done eq False) )
		kill("jbed.exe")
		call create_ini
	EndIf
EndWhile


Sub validate_ini
	if FileExists ( ini_file )
		split(ReadFile(ini_file),"|", True, opera_version_ini, jbed_exe_ini, jbed_params_ini, direct_address_input)
		if ( (opera_version_ini eq "") OR (jbed_exe_ini eq "") OR (jbed_params_ini eq "") OR (direct_address_input eq "") )
			error_msg = ini_file &" is invalid.^NL^^NL^"
			error_msg = error_msg & "Re-detect Opera Mini settings?"
			if (question(error_msg, MortScriptVersion(), "YesNo") eq No)
				exit
			else
				ini_ok = False
			EndIf
		else
			ini_ok = True
		EndIf
	EndIf
EndSub

Sub create_ini
	ShowWaitCursor
	opera40_string = "Opera Mini,"
	opera41_string = "Opera Mini 4.1,"
	
	if ( regvalueexists("HKCR","jarfile\Shell\Open\Command","") )
		jbed_exe_ini = Part(RegRead("HKCR","jarfile\Shell\Open\Command",""),"""",2,1)
		if (Find(jbed_exe_ini,"jbed") = 0)
			HideWaitCursor
			message ("Jbed not found.", MortScriptVersion())
			exit
		elseif not (FileExists ( jbed_exe_ini ))
			HideWaitCursor
			message ("File '"& jbed_exe_ini &"' not found.", MortScriptVersion())
			exit
		EndIf
	else
		HideWaitCursor
		message("Registry key 'HKCR\jarfile\Shell\Open\Command' missing.", MortScriptVersion())
		exit
	EndIf

	if ( regvalueexists("HKCR","jarfile\Shell\Save\Save Location","") )
		utf_filename = RegRead("HKCR","jarfile\Shell\Save\Save Location","") & "\selector.utf"
	else
		utf_filename = replace(jbed_exe_ini, "jbed.exe" , "Appdb\selector.utf")
	EndIf
	
	if not (FileExists (utf_filename))
		HideWaitCursor
		message ("File '"& utf_filename &"' not found.", MortScriptVersion())
		exit
	else
		utf_file = ReadFile(utf_filename)
	endif
	
	linenum = 0
	opera_count = 0

	ForEach line in split (utf_file, "^LF^", 1)
		linenum = linenum + 1
		opera_version_found = "unknown"
		prog_id = ""
					
		If (Find(line,"suite=" & opera40_string) ne 0)
			opera_version_found = "4.0"
		ElseIf (Find(line,"suite=" & opera41_string) ne 0)
			opera_version_found = "4.1"
		EndIf
		
		If ( opera_version_found ne "unknown" )
			prog_line = Part( utf_file,"^LF^",linenum+3,1)
			prog_line_position = find(prog_line,"root=")
			if (prog_line_position ne 0)
				#prog_id = replace(substr(prog_line, prog_line_position+5,5), ",", "")
				prog_id = SubStr( prog_line , Find(prog_line,"=")+1 , (Find(prog_line,"_")+1)-(Find(prog_line,"=")+1) )
				if (prog_id ne "")
					jbed_params_ini = "-run " & prog_id
					opera_count = opera_count + 1
					opera_array[opera_count] = opera_version_found &"|"& jbed_exe_ini &"|"& jbed_params_ini
				EndIf
			EndIf
		EndIf

	EndForEach
	HideWaitCursor

	opera_array_choice = 1
	
	If (opera_count = 0)
		message ("Opera Mini does not appear to be installed.", MortScriptVersion())
		exit
	ElseIf (opera_count = 1)
		opera_array_choice = opera_count
		ini_ok = True
	Else
		
		idx = choice(MortScriptVersion(), "Which Opera Mini version do you want to run by default?", 0, 0, opera_array)
		if (idx = 0)
			exit
		Else
			opera_array_choice = idx
			ini_ok = True
		EndIf
	EndIf
	
	direct_address_input = False
	If (ini_ok eq True)
		split(opera_array[opera_array_choice],"|", True, opera_version_ini, jbed_exe_ini, jbed_params_ini)
		if (opera_version_ini eq "4.1")
			if (question("In Opera Mini 4.1, do you have Direct Address Input enabled?^NL^(It's enabled by default.)", MortScriptVersion(), "YesNo") eq Yes)
				direct_address_input = True
			Else
				direct_address_input = False
			EndIf
		EndIf
		WriteFile (ini_file, opera_version_ini&"|"&jbed_exe_ini&"|"&jbed_params_ini&"|"&direct_address_input)
	EndIf
Endsub


Sub StartOM

	# Started from link so always check its state.
	If (url ne "")
		kill("jbed.exe")
		Run(jbed_exe_ini, jbed_params_ini)
		Call waitForColor
	# Is already running so probably started correctly before
	# so no need to restart it and check if it ran correctly.
	ElseIf ( ProcExists("jbed.exe") )
		Run(jbed_exe_ini, jbed_params_ini)
		loop_done = True
		main_loop_done = True
	# Is not running so possibly a first time start or
	# right after a setting re-detect to check if it ran correctly.
	Else
		Run(jbed_exe_ini, jbed_params_ini)
		Call waitForColor
	EndIf

	if ( (url ne "") AND (ini_ok eq True) )
		sleep(wait_time_between_keys)
		SendLeftSoft
		Sleep(wait_time_between_keys)
		SendLeftSoft
		Sleep(wait_time_between_keys)
		
		if (opera_version_ini eq "4.1" AND direct_address_input eq True)
			sendup
			Sleep(wait_time_between_keys)
			sendup
			Sleep(wait_time_between_keys)
			sendcr
			Sleep(wait_time_between_keys)
		Endif

		Call waitForNotColor

		If (ini_ok eq True)
			SetClipText(url)
		
			SendHome ("",1,0)
			sleep(wait_time_between_keys)
			SendEnd ("",1,1)
			sleep(wait_time_between_keys)
		
			SendCtrlKey("V")
			Sleep(wait_time_between_keys)
			SendLeftSoft
			sleep(wait_time_between_keys)
	
			if (opera_version_ini eq "4.1" AND direct_address_input eq True)
				sendcr
			endif			
		endif
		
	endif
EndSub

sub waitForColor
	loop_count = 0
	loop_done = False
	ShowWaitCursor
	while (loop_done = False)
		checkColor = colorat(checkPixelx,checkPixely)
		if ( (checkColor eq operaRed) OR (checkColor eq operaBlue) )
			loop_done = True
			main_loop_done = True
			HideWaitCursor
		ElseIf (loop_count >= wait_time_for_opera * 2)
			HideWaitCursor
			error_msg = "Did not find Opera Mini running after " & wait_time_for_opera &" seconds.^NL^Note: Landscape mode not supported.^NL^^NL^"
			error_msg = error_msg & "Re-detect Opera Mini settings and Retry?"
			if (question(error_msg, MortScriptVersion(), "YesNo") eq No)
				exit
			Else
				ini_ok = False
				loop_done = True
			EndIf
		Else
			sleep(500)
			loop_count = loop_count + 1
		EndIf
	endwhile
endsub

sub waitForNotColor
	loop_count = 0
	loop_done = False
	ShowWaitCursor
	while (loop_done = False)
		checkColor = colorat(checkPixelx,checkPixely)
		if ( (checkColor ne operaRed) AND (checkColor ne operaBlue) )
			loop_done = True
			main_loop_done = True
			HideWaitCursor
		ElseIf (loop_count >= wait_time_for_address * 2)
			HideWaitCursor
			error_msg = "Did not find the address input window after "& wait_time_for_address &" seconds.^NL^^NL^Re-detect Opera Mini settings and Retry?"
			if (question(error_msg, MortScriptVersion(), "YesNo") eq No)
				exit
			Else
				main_loop_done = False
				ini_ok = False
				loop_done = True
			EndIf
		Else
			sleep(500)
			loop_count = loop_count + 1
		EndIf
	endwhile
endsub
 
Last edited:

prscott1

Senior Member
Nov 5, 2007
807
23
Houston
Most of the JVMs I've seen will have that registry entry. Perhaps the designer of your rom left it out by mistake. Since you didn't say you got an error for 'HKCR\jarfile\Shell\Open\Command', I'll assume you have that entry. If that is so, check out my new version below, which does more requirements checking and may resolve your issue.



Okay, I'm looking through my registry and am really confused now. I don't have the HKCR\jarfile\Shell\open\command either.
Even though I am running esmertec jbed build 20070802.2.1, I see that I do have the following registry item:
HKCR\jmm.jadfile\shell\Open\Command - but I don't have a jmm.exe in my windows folder only a jbed.exe (and jbed.exe.0409.mui file). there are two jmmxxxx.dll files. I wonder if this registry item was left in the ROM by mistake when he added jbed.

Is there any harm that I add these keys to registry?

(I searched my entire registry for jbed.exe and found no matches.)jj

edit: I went ahead and changed jmm.jadfile to jarfile. And I changed the default value in command to jbed.exe "%1". I'm getting closer - maybe? Now I get the mortscript error: 4.1.1.7 window title, "Jbed not found". What other registry items should I add? Sorry to be a pain.
 
Last edited:

JZ SmartMort

Senior Member
Mar 24, 2008
784
16
Burbank
Okay, I'm looking through my registry and am really confused now. I don't have the HKCR\jarfile\Shell\open\command either.
Even though I am running esmertec jbed build 20070802.2.1, I see that I do have the following registry item:
HKCR\jmm.jadfile\shell\Open\Command - but I don't have a jmm.exe in my windows folder only a jbed.exe (and jbed.exe.0409.mui file). there are two jmmxxxx.dll files. I wonder if this registry item was left in the ROM by mistake when he added jbed.

Is there any harm that I add these keys to registry?

(I searched my entire registry for jbed.exe and found no matches.)jj

edit: I went ahead and changed jmm.jadfile to jarfile. And I changed the default value in command to jbed.exe "%1". I'm getting closer - maybe? Now I get the mortscript error: 4.1.1.7 window title, "Jbed not found". What other registry items should I add? Sorry to be a pain.

I'm not sure why you're messing with "JMM" stuff, because that's TAO Java, not JBed. Here are the registry keys you need for JBed to work with both badbob001's scripts and my scripts.

"HKCR\jarfile\Shell\Save\Save Location" - this value should take you to a folder that contains a file called selector.utf, make sure it exists.

"HKCR\jarfile\Shell\Open\Command" - this value should lead you to a jbed.exe file.
 
Last edited:

badbob001

Senior Member
Mar 28, 2005
320
17
PART 1/2

I don't really know all the registry details that JVMs use, so I can't really tell you what registry changes to make. My HKCR\jarfile\Shell\open\command has something complicated like:
"\Windows\jbed.exe" -DFile.maxStorageSize=20M -ginstall "file:\%1"
but I didn't put that there, the jbed installer did.

So side-stepping all that mess, I've updated my script to behave this way:
If HKCR\jarfile\Shell\open\command does not exist, does not refer to jbed, or refers to an invalid file, a file selection dialog will appear allowing you to tell it where jbed.exe is.

Selector.utf's location is first read from registry, but if that entry is not there, it will assume it's in subfolder \Appdb\ from where jbed.exe is.

I also liked JZ's script of making the necessary registry changes so Opera Mini is opened for links. If the .ini file is missing, the script will also check if registry changes are needed and give you the option to:
1. Use Opera Mini for llinks
2. Use IE for links
3. Skip this step

If 1 or 2 is chosen, a backup of the registry parts to be changed are stored in a backup file in the same location as the script. If you want to see this dialog window again, simply delete your ini file first.

Registry changes affect these keys:
[HKEY_CLASSES_ROOT\http\Shell\Open\Command]
[HKEY_CLASSES_ROOT\https\Shell\Open\Command]
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shell\Rai\:DEFBROWSER]

Damn, the code is too long to fit in one post. At this rate, this script is going to download and install jbed and Opera Mini for you. :)

Part 1 of 2
Code:
wait_time_for_opera = 10
 #default = 10 seconds

wait_time_for_address = 2
 #default = 2 seconds

wait_time_between_keys = 100
 #default = 100 milliseconds

operaRed =  rgb(107, 12, 8)
operaBlue = rgb(247, 243, 247)
checkPixelx = 0
checkPixely = 0
ini_file = SystemPath("ScriptPath") &"\"& SystemPath("ScriptName") &".ini"
mort_exe = SystemPath("ScriptExe") &"\MortScript.exe"
this_script = SystemPath("ScriptPath") &"\"& SystemPath("ScriptName") & SystemPath("ScriptExt")

if (substr(url,1,1) eq " ")
	url = substr(url,2)
EndIf

If (url ne "")
	If (Find("file://", ToLower(url)))
		Run("\Windows\iexplore.exe", url)
		exit
	EndIf
EndIf

main_loop_done = False
while(main_loop_done eq False)
	ini_ok = False
	call validate_ini
	if ( (ini_ok eq True) AND (main_loop_done eq False) )
		call startOM
	EndIf
	if ( (ini_ok eq False) AND (main_loop_done eq False) )
		kill("jbed.exe")
		call create_ini
	EndIf
EndWhile


Sub create_ini
	ShowWaitCursor
	opera40_string = "Opera Mini,"
	opera41_string = "Opera Mini 4.1,"
	
	if ( regvalueexists("HKCR","jarfile\Shell\Open\Command","") )
		jbed_exe_ini = Part(RegRead("HKCR","jarfile\Shell\Open\Command",""),"""",2,1)
		if (Find(jbed_exe_ini,"jbed") = 0)
			HideWaitCursor
			jbed_exe_ini = SelectFile( MortScriptVersion(), False, "*.exe", "[a]Please locate your Jbed.exe:")
			if ( jbed_exe_ini eq "" )
				message("Jbed.exe selection cancelled.", MortScriptVersion())
				exit
			EndIf
		elseif not (FileExists ( jbed_exe_ini ))
			HideWaitCursor
			jbed_exe_ini = SelectFile( MortScriptVersion(), False, "*.exe", "[b]Please locate your Jbed.exe:")
			if ( jbed_exe_ini eq "" )
				message("Jbed.exe selection cancelled.", MortScriptVersion())
				exit
			EndIf
		EndIf
	else
		HideWaitCursor
		jbed_exe_ini = SelectFile( MortScriptVersion(), False, "*.exe", "[c]Please locate your Jbed.exe:")
		if ( jbed_exe_ini eq "" )
			message("Jbed.exe selection cancelled.", MortScriptVersion())
			exit
		EndIf
	EndIf

	if ( regvalueexists("HKCR","jarfile\Shell\Save\Save Location","") )
		utf_filename = RegRead("HKCR","jarfile\Shell\Save\Save Location","") & "\selector.utf"
	else
		utf_filename = replace(jbed_exe_ini, "jbed.exe" , "Appdb\selector.utf")
	EndIf
	
	if not (FileExists (utf_filename))
		HideWaitCursor
		message ("File '"& utf_filename &"' not found.", MortScriptVersion())
		exit
	else
		utf_file = ReadFile(utf_filename)
	endif
	
	linenum = 0
	opera_count = 0

	ForEach line in split (utf_file, "^LF^", 1)
		linenum = linenum + 1
		opera_version_found = "unknown"
		prog_id = ""
					
		If (Find(line,"suite=" & opera40_string) ne 0)
			opera_version_found = "4.0"
		ElseIf (Find(line,"suite=" & opera41_string) ne 0)
			opera_version_found = "4.1"
		EndIf
		
		If ( opera_version_found ne "unknown" )
			prog_line = Part( utf_file,"^LF^",linenum+3,1)
			prog_line_position = find(prog_line,"root=")
			if (prog_line_position ne 0)
				prog_id = SubStr( prog_line , Find(prog_line,"=")+1 , (Find(prog_line,"_")+1)-(Find(prog_line,"=")+1) )
				if (prog_id ne "")
					jbed_params_ini = "-run " & prog_id
					opera_count = opera_count + 1
					opera_array[opera_count] = opera_version_found &"|"& jbed_exe_ini &"|"& jbed_params_ini
				EndIf
			EndIf
		EndIf

	EndForEach
	HideWaitCursor

	opera_array_choice = 1
	
	If (opera_count = 0)
		message ("Opera Mini does not appear to be installed.", MortScriptVersion())
		exit
	ElseIf (opera_count = 1)
		opera_array_choice = opera_count
		ini_ok = True
	Else
		
		idx = choice(MortScriptVersion(), "Which Opera Mini version do you want to run by default?", 0, 0, opera_array)
		if (idx = 0)
			exit
		Else
			opera_array_choice = idx
			ini_ok = True
		EndIf
	EndIf
	
	direct_address_input = False
	If (ini_ok eq True)
		split(opera_array[opera_array_choice],"|", True, opera_version_ini, jbed_exe_ini, jbed_params_ini)
		if (opera_version_ini eq "4.1")
			if (question("In Opera Mini 4.1, do you have Direct Address Input enabled?^NL^(It's enabled by default.)", MortScriptVersion(), "YesNo") eq Yes)
				direct_address_input = True
			Else
				direct_address_input = False
			EndIf
		EndIf
	EndIf
	
	browser_http_update  = """"& mort_exe &""" """& this_script &""" url=""%1"""
	browser_https_update = """"& mort_exe &""" """& this_script &""" url=""%1"""
	browser_def_update   = """"& mort_exe &""" """& this_script &""" url="""

	browser_http_ie  = """iexplore.exe %1"""
	browser_https_ie = """iexplore.exe %1"""
	browser_def_ie   = """iexplore.exe"""

	browser_reg_update = False
	if ( regvalueexists("HKCR","http\Shell\Open\Command","") )
		browser_http  = RegRead( "HKCR","http\Shell\Open\Command","" )
		if (browser_http ne browser_http_update)
			browser_reg_update = True
		EndIf
	Else
		browser_reg_update = True
	EndIf
			
	if ( regvalueexists("HKCR","https\Shell\Open\Command","") )
		browser_https  = RegRead( "HKCR","https\Shell\Open\Command","" )
		if (browser_https ne browser_https_update)
			browser_reg_update = True
		EndIf
	Else
		browser_reg_update = True
	EndIf
	
	if ( regvalueexists("HKLM","SOFTWARE\Microsoft\Shell\Rai\:DEFBROWSER","1") )
		browser_def  = RegRead( "HKLM","SOFTWARE\Microsoft\Shell\Rai\:DEFBROWSER","1" )
		if (browser_def ne browser_def_update)
			browser_reg_update = True
		EndIf
	Else
		browser_reg_update = True
	EndIf

	if ( (browser_reg_update eq True) OR (not FileExists(ini_file)) )
		browser_reg_update_array[1] = "Use Opera Mini for links."
		browser_reg_update_array[2] = "Use IE for links."
		browser_reg_update_array[3] = "Skip this step."
		
		If (browser_reg_update eq True)
			choice_msg = "Registry needs to be updated so links are handled by Opera Mini."
		Else
			choice_msg = "Links are currrently handled by Opera Mini. Change?"
		EndIf
		Choice(MortScriptVersion(), choice_msg, browser_reg_update_array)
			Case(0)
				exit
			Case(1)
				bak_file = SystemPath("ScriptPath") &"\"& SystemPath("ScriptName") &"_reg_backup.txt"
				WriteFile (bak_file, "["& formattime("y/m/d h:i A") &"] 'Use Opera Mini for links' chosen. Backup before change:^NL^", True)
				WriteFile (bak_file, "[HKEY_CLASSES_ROOT\http\Shell\Open\Command]^NL^@="& browser_http &"^NL^", True)
				WriteFile (bak_file, "[HKEY_CLASSES_ROOT\https\Shell\Open\Command]^NL^@="& browser_https &"^NL^", True)
				WriteFile (bak_file, "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shell\Rai\:DEFBROWSER]^NL^""1""="& browser_def &"^NL^", True)
				WriteFile (bak_file, "^NL^", True)
				RegWriteString( "HKCR","http\Shell\Open\Command","",browser_http_update)
				RegWriteString( "HKCR","https\Shell\Open\Command","",browser_https_update)
				RegWriteString( "HKLM","SOFTWARE\Microsoft\Shell\Rai\:DEFBROWSER","1",browser_def_update)
			Case(2)
				bak_file = SystemPath("ScriptPath") &"\"& SystemPath("ScriptName") &"_reg_backup.txt"
				WriteFile (bak_file, "["& formattime("y/m/d h:i A") &"] 'Use IE for links' chosen. Backup before change:^NL^", True)
				WriteFile (bak_file, "[HKEY_CLASSES_ROOT\http\Shell\Open\Command]^NL^@="& browser_http &"^NL^", True)
				WriteFile (bak_file, "[HKEY_CLASSES_ROOT\https\Shell\Open\Command]^NL^@="& browser_https &"^NL^", True)
				WriteFile (bak_file, "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shell\Rai\:DEFBROWSER]^NL^""1""="& browser_def &"^NL^", True)
				WriteFile (bak_file, "^NL^", True)
				RegWriteString( "HKCR","http\Shell\Open\Command","",browser_http_ie)
				RegWriteString( "HKCR","https\Shell\Open\Command","",browser_https_ie)
				RegWriteString( "HKLM","SOFTWARE\Microsoft\Shell\Rai\:DEFBROWSER","1",browser_def_ie)
			Case(3)
				#do nothing
		EndChoice
	EndIf

	WriteFile (ini_file, opera_version_ini&"|"&jbed_exe_ini&"|"&jbed_params_ini&"|"&direct_address_input)
Endsub
 
Last edited:

badbob001

Senior Member
Mar 28, 2005
320
17
Part 2/2

Code:
Sub validate_ini
	if FileExists ( ini_file )
		split(ReadFile(ini_file),"|", True, opera_version_ini, jbed_exe_ini, jbed_params_ini, direct_address_input)
		if ( (opera_version_ini eq "") OR (jbed_exe_ini eq "") OR (jbed_params_ini eq "") OR (direct_address_input eq "") )
			error_msg = ini_file &" is invalid.^NL^^NL^"
			error_msg = error_msg & "Re-detect Opera Mini settings?"
			if (question(error_msg, MortScriptVersion(), "YesNo") eq No)
				exit
			else
				ini_ok = False
			EndIf
		else
			ini_ok = True
		EndIf
	EndIf
EndSub


Sub StartOM
	# Started from link so always check its state.
	If (url ne "")
		kill("jbed.exe")
		Run(jbed_exe_ini, jbed_params_ini)
		Call waitForColor
	# Is already running so probably started correctly before
	# so no need to restart it and check if it ran correctly.
	ElseIf ( ProcExists("jbed.exe") )
		Run(jbed_exe_ini, jbed_params_ini)
		loop_done = True
		main_loop_done = True
	# Is not running so possibly a first time start or
	# right after a setting re-detect to check if it ran correctly.
	Else
		Run(jbed_exe_ini, jbed_params_ini)
		Call waitForColor
	EndIf

	if ( (url ne "") AND (ini_ok eq True) )
		sleep(wait_time_between_keys)
		SendLeftSoft
		Sleep(wait_time_between_keys)
		SendLeftSoft
		Sleep(wait_time_between_keys)
		
		if (opera_version_ini eq "4.1" AND direct_address_input eq True)
			sendup
			Sleep(wait_time_between_keys)
			sendup
			Sleep(wait_time_between_keys)
			sendcr
			Sleep(wait_time_between_keys)
		Endif

		Call waitForNotColor

		If (ini_ok eq True)
			SetClipText(url)
		
			SendHome ("",1,0)
			sleep(wait_time_between_keys)
			SendEnd ("",1,1)
			sleep(wait_time_between_keys)
		
			SendCtrlKey("V")
			Sleep(wait_time_between_keys)
			SendLeftSoft
			sleep(wait_time_between_keys)
	
			if (opera_version_ini eq "4.1" AND direct_address_input eq True)
				sendcr
			endif			
		endif
		
	endif
EndSub


sub waitForColor
	loop_count = 0
	loop_done = False
	ShowWaitCursor
	while (loop_done = False)
		checkColor = colorat(checkPixelx,checkPixely)
		if ( (checkColor eq operaRed) OR (checkColor eq operaBlue) )
			loop_done = True
			main_loop_done = True
			HideWaitCursor
		ElseIf (loop_count >= wait_time_for_opera * 2)
			HideWaitCursor
			error_msg = "Did not find Opera Mini running after " & wait_time_for_opera &" seconds.^NL^Note: Landscape mode not supported.^NL^^NL^"
			error_msg = error_msg & "Re-detect Opera Mini settings and Retry?"
			if (question(error_msg, MortScriptVersion(), "YesNo") eq No)
				exit
			Else
				ini_ok = False
				loop_done = True
			EndIf
		Else
			sleep(500)
			loop_count = loop_count + 1
		EndIf
	endwhile
endsub


sub waitForNotColor
	loop_count = 0
	loop_done = False
	ShowWaitCursor
	while (loop_done = False)
		checkColor = colorat(checkPixelx,checkPixely)
		if ( (checkColor ne operaRed) AND (checkColor ne operaBlue) )
			loop_done = True
			main_loop_done = True
			HideWaitCursor
		ElseIf (loop_count >= wait_time_for_address * 2)
			HideWaitCursor
			error_msg = "Did not find the address input window after "& wait_time_for_address &" seconds.^NL^^NL^Re-detect Opera Mini settings and Retry?"
			if (question(error_msg, MortScriptVersion(), "YesNo") eq No)
				exit
			Else
				main_loop_done = False
				ini_ok = False
				loop_done = True
			EndIf
		Else
			sleep(500)
			loop_count = loop_count + 1
		EndIf
	endwhile
endsub
 

JZ SmartMort

Senior Member
Mar 24, 2008
784
16
Burbank
I also liked JZ's script of making the necessary registry changes so Opera Mini is opened for links. If the .ini file is missing, the script will also check if registry changes are needed and give you the option to:
1. Use Opera Mini for llinks
2. Use IE for links
3. Skip this step

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shell\Rai\;DEFBROWSER]

badbob001, do you know what the DEFBROWSER location is for or when it's used. My SmartPhone didn't have it by default, neither did the Microsoft emulator images. I do see it referenced on websites though... so far, HTTP & HTTPS reg entries have worked for pretty much everything.

BTW, why did you go off into an INI, old-school :)
 
Last edited:

tmknight

Senior Member
Mar 27, 2007
424
32
Georgia
For those wanting a choice of browser

OK, I like how this is going. Since I and some other folks like to be able to choose which browser we use, I cobbled together Werner's original code and badbob001's.

I still want to have OM 4.0 available since 4.1 is beta hence the reference and choice for it, so you still have one section where you need to make a change to the script based on the selector position of whatever other version of OM you may want to have available to you.

The "Cancel" option isn't really as relevant anymore since that is built into MortScript (OK and Cancel at bottom of window). The "Copy to clipboard" may still be useful to folks, but probably can go to0. Left both in since that was the original code.

Code:
#input selector position of Opera Mini 4.0 or any other version of OM that you may want to use
OMv4 = "-run s0_"

if (substr(url,1,1) eq " ")
url = substr(url,2)
EndIf

list[1] = "Open in Opera Mini 4.1"
list[2] = "Open in Pocket IE"
list[3] = "Open in Opera Mini 4.0"
list[4] = "Copy to clipboard"
list[5] = "Cancel"
Choice("With this link...", url, list)

Case(1)
Call OpenOM41
Case(2)
Run("\Windows\iexplore.exe", url)
Case(3)
Call OpenOM40
Case(4)
SetClipText(url)
Case(0,5)
Exit
EndChoice


Sub OpenOM41
wait_time_for_opera = 10
 #default = 10 seconds

wait_time_for_address = 2
 #default = 2 seconds

wait_time_between_keys = 100
 #default = 100 milliseconds

operaRed =  rgb(107, 12, 8)
operaBlue = rgb(247, 243, 247)
checkPixelx = 0
checkPixely = 0
ini_file = SystemPath("ScriptPath") &"\"& SystemPath("ScriptName") &".ini"

if (substr(url,1,1) eq " ")
	url = substr(url,2)
EndIf

If (url ne "")
	If (Find("file://", ToLower(url)))
		Run("\Windows\iexplore.exe", url)
		exit
	EndIf
EndIf

main_loop_done = False
while(main_loop_done eq False)
	ini_ok = False
	call validate_ini
	if ( (ini_ok eq True) AND (main_loop_done eq False) )
		call startOM
	EndIf
	if ( (ini_ok eq False) AND (main_loop_done eq False) )
		kill("jbed.exe")
		call create_ini
	EndIf
EndWhile
EndSub

Sub validate_ini
	if FileExists ( ini_file )
		split(ReadFile(ini_file),"|", True, opera_version_ini, jbed_exe_ini, jbed_params_ini, direct_address_input)
		if ( (opera_version_ini eq "") OR (jbed_exe_ini eq "") OR (jbed_params_ini eq "") OR (direct_address_input eq "") )
			error_msg = ini_file &" is invalid.^NL^^NL^"
			error_msg = error_msg & "Re-detect Opera Mini settings?"
			if (question(error_msg, MortScriptVersion(), "YesNo") eq No)
				exit
			else
				ini_ok = False
			EndIf
		else
			ini_ok = True
		EndIf
	EndIf
EndSub

Sub create_ini
	ShowWaitCursor
	opera40_string = "Opera Mini,"
	opera41_string = "Opera Mini 4.1,"
	
	if ( regvalueexists("HKCR","jarfile\Shell\Open\Command","") )
		jbed_exe_ini = Part(RegRead("HKCR","jarfile\Shell\Open\Command",""),"""",2,1)
		if (Find(jbed_exe_ini,"jbed") = 0)
			HideWaitCursor
			message ("Jbed not found.", MortScriptVersion())
			exit
		elseif not (FileExists ( jbed_exe_ini ))
			HideWaitCursor
			message ("File '"& jbed_exe_ini &"' not found.", MortScriptVersion())
			exit
		EndIf
	else
		HideWaitCursor
		message("Registry key 'HKCR\jarfile\Shell\Open\Command' missing.", MortScriptVersion())
		exit
	EndIf

	if ( regvalueexists("HKCR","jarfile\Shell\Save\Save Location","") )
		utf_filename = RegRead("HKCR","jarfile\Shell\Save\Save Location","") & "\selector.utf"
	else
		utf_filename = replace(jbed_exe_ini, "jbed.exe" , "Appdb\selector.utf")
	EndIf
	
	if not (FileExists (utf_filename))
		HideWaitCursor
		message ("File '"& utf_filename &"' not found.", MortScriptVersion())
		exit
	else
		utf_file = ReadFile(utf_filename)
	endif
	
	linenum = 0
	opera_count = 0

	ForEach line in split (utf_file, "^LF^", 1)
		linenum = linenum + 1
		opera_version_found = "unknown"
		prog_id = ""
					
		If (Find(line,"suite=" & opera40_string) ne 0)
			opera_version_found = "4.0"
		ElseIf (Find(line,"suite=" & opera41_string) ne 0)
			opera_version_found = "4.1"
		EndIf
		
		If ( opera_version_found ne "unknown" )
			prog_line = Part( utf_file,"^LF^",linenum+3,1)
			prog_line_position = find(prog_line,"root=")
			if (prog_line_position ne 0)
				#prog_id = replace(substr(prog_line, prog_line_position+5,5), ",", "")
				prog_id = SubStr( prog_line , Find(prog_line,"=")+1 , (Find(prog_line,"_")+1)-(Find(prog_line,"=")+1) )
				if (prog_id ne "")
					jbed_params_ini = "-run " & prog_id
					opera_count = opera_count + 1
					opera_array[opera_count] = opera_version_found &"|"& jbed_exe_ini &"|"& jbed_params_ini
				EndIf
			EndIf
		EndIf

	EndForEach
	HideWaitCursor

	opera_array_choice = 1
	
	If (opera_count = 0)
		message ("Opera Mini does not appear to be installed.", MortScriptVersion())
		exit
	ElseIf (opera_count = 1)
		opera_array_choice = opera_count
		ini_ok = True
	Else
		
		idx = choice(MortScriptVersion(), "Which Opera Mini version do you want to run by default?", 0, 0, opera_array)
		if (idx = 0)
			exit
		Else
			opera_array_choice = idx
			ini_ok = True
		EndIf
	EndIf
	
	direct_address_input = False
	If (ini_ok eq True)
		split(opera_array[opera_array_choice],"|", True, opera_version_ini, jbed_exe_ini, jbed_params_ini)
		if (opera_version_ini eq "4.1")
			if (question("In Opera Mini 4.1, do you have Direct Address Input enabled?^NL^(It's enabled by default.)", MortScriptVersion(), "YesNo") eq Yes)
				direct_address_input = True
			Else
				direct_address_input = False
			EndIf
		EndIf
		WriteFile (ini_file, opera_version_ini&"|"&jbed_exe_ini&"|"&jbed_params_ini&"|"&direct_address_input)
	EndIf
Endsub


Sub StartOM

	# Started from link so always check its state.
	If (url ne "")
		kill("jbed.exe")
		Run(jbed_exe_ini, jbed_params_ini)
		Call waitForColor
	# Is already running so probably started correctly before
	# so no need to restart it and check if it ran correctly.
	ElseIf ( ProcExists("jbed.exe") )
		Run(jbed_exe_ini, jbed_params_ini)
		loop_done = True
		main_loop_done = True
	# Is not running so possibly a first time start or
	# right after a setting re-detect to check if it ran correctly.
	Else
		Run(jbed_exe_ini, jbed_params_ini)
		Call waitForColor
	EndIf

	if ( (url ne "") AND (ini_ok eq True) )
		sleep(wait_time_between_keys)
		SendLeftSoft
		Sleep(wait_time_between_keys)
		SendLeftSoft
		Sleep(wait_time_between_keys)
		
		if (opera_version_ini eq "4.1" AND direct_address_input eq True)
			sendup
			Sleep(wait_time_between_keys)
			sendup
			Sleep(wait_time_between_keys)
			sendcr
			Sleep(wait_time_between_keys)
		Endif

		Call waitForNotColor

		If (ini_ok eq True)
			SetClipText(url)
		
			SendHome ("",1,0)
			sleep(wait_time_between_keys)
			SendEnd ("",1,1)
			sleep(wait_time_between_keys)
		
			SendCtrlKey("V")
			Sleep(wait_time_between_keys)
			SendLeftSoft
			sleep(wait_time_between_keys)
	
			if (opera_version_ini eq "4.1" AND direct_address_input eq True)
				sendcr
			endif			
		endif
		
	endif
EndSub

sub waitForColor
	loop_count = 0
	loop_done = False
	ShowWaitCursor
	while (loop_done = False)
		checkColor = colorat(checkPixelx,checkPixely)
		if ( (checkColor eq operaRed) OR (checkColor eq operaBlue) )
			loop_done = True
			main_loop_done = True
			HideWaitCursor
		ElseIf (loop_count >= wait_time_for_opera * 2)
			HideWaitCursor
			error_msg = "Did not find Opera Mini running after " & wait_time_for_opera &" seconds.^NL^Note: Landscape mode not supported.^NL^^NL^"
			error_msg = error_msg & "Re-detect Opera Mini settings and Retry?"
			if (question(error_msg, MortScriptVersion(), "YesNo") eq No)
				exit
			Else
				ini_ok = False
				loop_done = True
			EndIf
		Else
			sleep(500)
			loop_count = loop_count + 1
		EndIf
	endwhile
endsub

sub waitForNotColor
	loop_count = 0
	loop_done = False
	ShowWaitCursor
	while (loop_done = False)
		checkColor = colorat(checkPixelx,checkPixely)
		if ( (checkColor ne operaRed) AND (checkColor ne operaBlue) )
			loop_done = True
			main_loop_done = True
			HideWaitCursor
		ElseIf (loop_count >= wait_time_for_address * 2)
			HideWaitCursor
			error_msg = "Did not find the address input window after "& wait_time_for_address &" seconds.^NL^^NL^Re-detect Opera Mini settings and Retry?"
			if (question(error_msg, MortScriptVersion(), "YesNo") eq No)
				exit
			Else
				main_loop_done = False
				ini_ok = False
				loop_done = True
			EndIf
		Else
			sleep(500)
			loop_count = loop_count + 1
		EndIf
	endwhile
endsub

Sub OpenOM40
If (ProcExists("jbed.exe"))
Run("\ExtendedROM\Esmertec Java\jbed.exe", OMv4)
sleep(3000)
Else
Run("\ExtendedROM\Esmertec Java\jbed.exe", OMv4)
sleep(8500)
EndIf

SendLeftSoft
Sleep(100)
SendLeftSoft
Sleep(100)

SetClipText(url)

SendEnd
SendHome("",0,1 )
Sleep(100)

SendCtrlKey("V")
Sleep(100)
SendLeftSoft
EndSub

Cheers!
 
Last edited:

badbob001

Senior Member
Mar 28, 2005
320
17
badbob001, do you know what the DEFBROWSER location is for or when it's used. My SmartPhone didn't have it by default, neither did the Microsoft emulator images. I do see it referenced on websites though... so far, HTTP & HTTPS reg entries have worked for pretty much everything.

BTW, why did you go off into an INI, old-school :)

The second post of this very thread (http://forum.xda-developers.com/showthread.php?t=347689#2) mentions that DEFBROWSER is used by WM6. Isn't your Cingular 3125 on WM5? Perhaps it's not really needed, but I'll just defer to Menneisyys' research.

It's much easier to check and delete an .ini file for testing. It's not REALLY an ini file since it's not in the standard ini format (mortscript has functions to read/write ini files but seemed overkill). Besides, it's scary messing with people's registry and it took me this long to finally write to it... with backups every time of course. Besides, I hate mysterious changes that programs may make all over the system. I like uninstall = delete folder.
 

prscott1

Senior Member
Nov 5, 2007
807
23
Houston
I'm not sure why you're messing with "JMM" stuff, because that's TAO Java, not JBed. Here are the registry keys you need for JBed to work with both badbob001's scripts and my scripts.

Thanks for a quick note. I basically deleted the jmm registry item and created jarfile items to match what you posted. I'll test again! Regards. :)
 

prscott1

Senior Member
Nov 5, 2007
807
23
Houston
I don't really know all the registry details that JVMs use, so I can't really tell you what registry changes to make. My HKCR\jarfile\Shell\open\command has something complicated like:
"\Windows\jbed.exe" -DFile.maxStorageSize=20M -ginstall "file:\%1"
but I didn't put that there, the jbed installer did.

Okay, I added quotes around my \windows\jbed.exe and that did the trick! Your old script works for me now!! :)

I guess my chef left the old tao registry items in there and didn't include the jbed ones. No big deal to add them once i knew what to add. You rock badbob!! Thanks.
 

badbob001

Senior Member
Mar 28, 2005
320
17
UPDATE
Moved zip to here, a new thread for it. Sorry for cluttering up this thread with my craziness. Menneisyys, you have the best ideas.

I've figured I'll need to zip up the code to post it here so I might as well make this the post WHERE IT WILL LIVE. I've also included some simple instructions since I'm sure people start skimming once a thread goes double-digits in page count.

04/10/2007: zip uploaded.
 
Last edited:

tmknight

Senior Member
Mar 27, 2007
424
32
Georgia
I suggest that the concept is still Werner's baby, but the execution has taken on a whole new life. I think a new thread is warranted and a link noted in the 1st two posts of this thread and referrer in the new thread to this one (ensuring credit is placed where credit is due).
 
Last edited:

JZ SmartMort

Senior Member
Mar 24, 2008
784
16
Burbank
I suggest that the concept is still Werner's baby, but the execution has taken on a whole new life. I think a new thread is warranted and a link noted in the 1st two posts of this thread and referrer int he new thread to this one (ensuring credit is placed where credit is due).

Menneisyys, thanks for sharing your research with us!!! It's all cuz of you that I keep perpetually enhancing my scripts, I want my life back :)

I agree with tmknight. I have a separate thread for my stuff. It makes it easier to maintain by editing. I post something here when I release a new version otherwise it's clutter.
 
Last edited: