Page 1 of 2
Getting a browser page address
Posted: Tue Mar 10, 2009 6:05 pm
by gyroscope
Hi, one of my future projects is a browser-external bookmarking prog, so I have two questions concerning this please:
• How do I get a copy of the web address showing in the browser address window (i.e via script in a button perhaps, rather than the user having to copy and paste it). Or might this not be possible from Rev?
• Is it possible, when launching a web URL from Rev to script for it to open into a new tab in the Browser and/or new window in the Browser?
Any help appreciated, thanks.

Posted: Wed Mar 11, 2009 12:30 am
by gyroscope
Hi, for my first question above, might it be done using revBrowserGet, does anyone know please, or is this function used only for the Rev-made browser?
I tried
Code: Select all
on mouseUp pMouseBtnNo
put revBrowserGet(url) into field "Field"
end mouseUp
and it doesn't like that. I suppose I have to indicate what the current open browser is (in my case, Safari), possibly?
Posted: Wed Mar 11, 2009 2:55 am
by Mark Smith
If you're talking about getting the current url from Safari, you'll need to use Applescript.
The 'revBrowser' handlers are only to do with rev's built in browser.
Posted: Wed Mar 11, 2009 9:02 am
by gyroscope
The 'revBrowser' handlers are only to do with rev's built in browser.
Thanks for confirming my suspicion there and your answer, Mark.
I guess if I wanted similar behaviour on a PC as well, I'd have to use the PC's equivalent of AppleScript, whatever that is; and both also for opening web pages in a new or tabbed window.

Posted: Wed Mar 11, 2009 1:59 pm
by SparkOut
Hi gyro,
this isn't going to be easy...
The only way I know to get the current url from the browser to be returned to Rev is as per Ken Ray's post here:
http://lists.runrev.com/pipermail/use-r ... 20513.html
Code: Select all
Set objApps = CreateObject("Shell.Application")
For Each objApp in objApps.Windows
If (objApp.Name = "Windows Internet Explorer") or _
(objApp.Name = "Microsoft Internet Explorer") Then
If objApp.LocationURL <> "" Then
WScript.Echo objApp.LocationURL
End If
End If
Next
I'm not aware of how vbscript or such could retrieve the url from any other browser.
To open a browser in a new tab is possible, but you'd have to test for the browsers...
On the Windows platform you can interrogate the registry key
Code: Select all
HKEY_CLASSES_ROOT\http\shell\open\command\
and return the default browser path.
If that is IE then you can run the following vbscript
Code: Select all
On Error resume next
result = "OK"
destinationURL = "http://www.runrev.com"
Set objShell = CreateObject("Shell.Application")
If Err <> 0 Then
result = "Error creating shell application"
End If
If result = "OK" Then
Set objShellWindows = objShell.Windows
If Err <> 0 Then
result = "Error getting windows collection"
End If
End If
If result = "OK" Then
Set objIE = objShellWindows.Item
If Err <> 0 Then
result = "Error getting windows item"
End If
End If
If result = "OK" Then
objIE.Navigate2 destinationURL
End If
If Err <> 0 Then
Set objIE = CreateObject("InternetExplorer.Application")
If Err <> 0 Then
result = "Error creating IE Application object"
Else
objIE.Visible = True
objIE.Navigate2 destinationURL
End If
End If
Set objIE = Nothing
Set objShellWindows = Nothing
Set objShell = Nothing
which should open the destinationURL in a new tab if IE7 is already open. If IE7 is not open then it will cause an error which is then handled by the second part of the code to create an IE instance and navigate to it.
I don't know what happens in any version other than IE7.
If the default browser is Firefox, then you can
Code: Select all
put "http://www.runrev.com" into tURL
put "start '' '<path to firefox.exe from registry>' '-new-tab' '" & tURL & "'" into tFirefox
replace "'" with quote in tFirefox
set the hideConsoleWindows to true
get shell (tFirefox)
Firefox has the -new-tab switch to open a destination in a new tab. (The extra pair of quotes between "start" and the path is to be a blank title for the (hidden) console window, otherwise it won't start).
Opera seems to have this behaviour by default, so if it's open it will go to a new tab on launching your url, or open itself with the url in the first tab if it's not already opened.
Code: Select all
put "http://www.runrev.com" into tURL
put "start '' '<Path to Opera from registry>' '" & tURL & "'" into tOpera
replace "'" with quote in tOpera
set the hideConsoleWindows to true
get shell (tOpera)
I don't know about any other browsers.
HTH
Posted: Wed Mar 11, 2009 2:37 pm
by gyroscope
Hi SparkOut
HTH
Only by 10 miles! Seriously, that's excellent all of that info and will be most useful when I finish the cross-platform version of the particular prog I have in mind, thank you muchly.
With the possibility of generating a reply similar to "What do you want, jam on it?!"

if there is any leads that you or someone else could provide concerning the alternate Appletalk scripts for Mac, that'd be brilliant. (Being a member of computer-sheltered-life.com I haven't had any dealings with Applescript).

Posted: Wed Mar 11, 2009 4:55 pm
by SparkOut
If I could help I would, but I don't have jam, sorry. I'm clueless about Macs and applescript.
Posted: Wed Mar 11, 2009 6:21 pm
by gyroscope
Aww, no jam, but thanks again for the bread and butter! (I think I might be overdoing this metaphor now...)

Posted: Wed Mar 11, 2009 6:30 pm
by Philhold
I use Yojimbo and have a "Bookmarklet" in my browser bookmarks toolbar, this is a Javascript. When I click on it a dialogue opens asking me to give it a name. I name it, click OK and it is put into Yojimbo.
http://anoved.net/bookmark_in_yojimbo.html
I just thought this might give you some ideas.
Cheers
Phil
Posted: Wed Mar 11, 2009 6:39 pm
by gyroscope
Thank you Phil, that looks interesting; I'm going to check it out in more detail now. It looks to be what I need.

Posted: Wed Mar 11, 2009 8:03 pm
by gyroscope
Unfortunately the script seems locked somehow; but I found a script from another Forum member:
http://forums.runrev.com/phpBB2/viewtopic.php?p=5713
So I put
Code: Select all
tell application "Safari"
URL of window 1
set myURL to the result
end tell
into a Field called "A" and
Code: Select all
on mouseUp
do cd fld "A" as appleScript
put result() into field "B"
end mouseUp
into a button script. But the result in field "B" says "execution error" so I've obviously done something wrong.
So two questions please:
1) Can anyone help to correct the above code so that it works and
2) Is putting AppleScript in a field and calling the script up via code the only way to use AppleScript in Rev, or might there be other methods?
Any help appreciated, thanks.
Posted: Wed Mar 11, 2009 8:24 pm
by SparkOut
It looks to me like the error is line :
do cd fld "A" as appleScript
which should be
do field "A" as appleScript
the "cd" you have in there looks like someone was editing out a reference to a card and left a bit of rubbish in.
[edit]On the other hand, perhaps I'm just talking absolute garbage. It works as "a card field" - but I've never seen that syntax used before myself! Live and learn![/edit]
You can put the script into a variable, or mostly I think people tend to put it into a custom property, particularly a button.
Then you can
Code: Select all
on mouseUp
do the cThirdPartyScript of me as "scriptType"
put the result into field "fldResult"
end mouseUp
With strict compilation mode on I've got used to putting the third party script type (in my case vbscript) in quotes. Even without strict compilation mode it seems not always to run successfully if I don't (on Windows).
Posted: Wed Mar 11, 2009 8:42 pm
by gyroscope
Thank you SparkOut (I thought you said you didn't have any jam

)
Unfortunately though it still doesn't work for me, as I get "alternate language not found".
Getting closer to a solution though, I'm certain...
Posted: Wed Mar 11, 2009 9:07 pm
by bn
Hi gyroscope,
put
Code: Select all
tell application "Safari"
set myURL to URL of document 1
return myURL
end tell
into field A. If you then do field A as in your script. If Safari is open and has an active window it will return the URL.
"cd field" is an old Hypercard remnant for compatibility reasons (hypercard used card field and background field. If you just said field Hypercard assumed a background field, so you had to explicitly tell it if you meant a card field) and does not hurt in this case but I would not use it, just use field as SparkOut suggested.
I like to listen to the local traffic news of the two of you
If you need help with applescript I can be of service to a certain degree.
regards
Bernd
Posted: Wed Mar 11, 2009 9:33 pm
by gyroscope
Hi Bernd, absolutely spot-on. It works just right, exactly what's needed. Thanks!
Interesting reading concerning an old Hypercard remnant. For interest, I was clearing out my garage the other day and found a water-damaged copy of Danny Goodman's The Complete Hypercard 2.2. I remember buying this in the early nineties (that'll be last century

) and kicked myself for not actually making much use of it (I was still trying to find my way around Lingo and suppose thought I'd confuse my little old brain by trying to learn a second Basic-type language, however similar).
I like to listen to the local traffic news of the two of you
A bit of jolly banter now and then always helps entertain the thread readers, I think!
If you need help with applescript I can be of service to a certain degree.
Thank you, Bernd. It'll be a while possibly though; I don't know if you've gathered from some of my posts that I have five (well, more than that now actually) definite app ideas on the go at the same time. My first project is 80% there, and the others range from 30 to 10%. I tend to jump from one to the other depending on... the weather, I suppose! So when appleScript is on the menu again for me, it'll be appreciated for your advice and help.
