Changing file actions depending on location

The subject line might not make as much sense as I'd like, but I'm having a tough day today (I think I left my brain next to my alarm clock this morning.)

Anyways, what I was wondering if it'd be possible to do, would be if different types of file actions could be location-dependent.

For example: double-clicking HTML/ASPX files in my sandbox location (D:\Sandbox) would open up my authoring application, passing through whatever files might be selected. Double-clicking HTML/ASPX files in on my dev server (X:) would instead open up my suite of browsers, again passing through whatever files might be selected. I wouldn't mind similar changes in behavior for my database development too (e.g., in the dev locations, open the console but in the prod locations, open the db application instead.)

I'm pretty sure Opus doesn't have that capability now & not even sure if anyone else would find such behavior useful. I'd also imagine it could be fairly difficult to code, although I could be wrong given Opus' versatility in terms of taking actions on files via drag-n-drop versus double-clicking, etc. And after all those waffling qualifiers, I'm going to sign off & slog through another meeting. :L

I can't think of a built-in way to accomplish that, but you could do it by configuring Opus to pass HTML/ASPX files to a script when they are double-clicked, and the script could then decide what to do with them based on where they are.

e.g. a Bit of VBScript could be used to do it.

Something like this, if set as the action for the Left double-click Event of the filetypes in question:

[code]Rename PATTERN * TO {alias|home} TYPE=files
@nodeselect
@script vbscript
Option Explicit

Function Rename_GetNewName(strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName)
Dim vbQuote
vbQuote = Chr(34)

Dim commandLine, home, path, shell
Set shell = CreateObject("WScript.Shell")
home = strNewName
strNewName = ""
path = LCase(strFilePath)

if InStr(path,"d:\sandbox") then
commandLine = vbQuote & "C:\Program Files\application1.exe" & vbQuote
elseif InStr(path,"x:") then
commandLine = vbQuote & "C:\Program Files\application2.exe" & vbQuote
else
commandLine = vbQuote & home & "dopusrt.exe" & vbQuote & " /cmd filetype open file"
end if

commandLine = commandLine & " " &_
vbQuote & strFilePath & "" & strFileName & vbQuote
shell.Run commandLine

End Function
[/code]

You'll want to edit the text above to provide the actual paths to your preferred apps:

For the stuff in the D:\Sandbox path:
commandLine = vbQuote & "C:\Program Files\application1.exe" & vbQuote

For the stuff in the X: path:
commandLine = vbQuote & "C:\Program Files\application2.exe" & vbQuote

For everything else; the way the rename script works passes the Opus home directory path to help the script find the path to dopusrt.exe... which it then calls to run the registered open action which should launch the default app for the filetype like should be happening whenever you currently double-click such files now.
commandLine = vbQuote & home & "dopusrt.exe" & vbQuote & " /cmd filetype open file"

...you could of course run something else in that last case as well. Up to you...

I must be exceptionally dense today, as I'm having both some conceptual and practical confusion (not to mention grammatical & spelling...)

  1. The entirety of the code you demoed should be inserted into the left double-click event for *.aspx files, correct? Even though there's a function definition in the code, that function doesn't need to live somewhere on system drives?

  2. Despite my confusion in #1, I did insert the code into the left double-click event for aspx files, modifying the application invocations as I thought they'd need to be. In testing, I'm receiving an error message to the effect that "access is denied" when attempting to rename the file. This occurs for file in either the sandbox or on DEV:. My modifications are delineated below; I am struggling mightly with both Chrome & Visual Studio in terms of what on earth they want passed to them and how. The help docs & online forum support presupposes a level of technical knowledge that alas seems to be beyond me. :frowning:

if InStr(path,"d:\websandbox\trunk") then
	commandLine = vbQuote & "C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" & vbQuote
	commandLine = commandLine & " " & vbQuote & strFilePath & "\" & strFileName & vbQuote
	commandLine = commandLine & " /Edit"
elseif InStr(path,"x:\") then
	commandLine = vbQuote & "C:\Documents and Settings\gbw1\Local Settings\Application Data\Google\Chrome\Application\chrome.exe" & vbQuote
	Clipboard COPYNAMES REGEXP x:\\(.*) http://web-dev-vm/humanservices/\1
	commandLine = commandLine & " " & vbQuote & {clip} & vbQuote
else
	commandLine = vbQuote & home & "dopusrt.exe" & vbQuote & " /cmd filetype open file"
end if

shell.Run commandLine

Anywho, I'm inclined to think that I've completely botched the rename somehow as the only files to do not throw the error message are *.master files. They, however, always open in Visual Studio, never in Chrome.

I appreciate your guidance thus far; I'll continue to wrestle with this on my own & if you have any suggestions as to how to correct my mistakes, I'd be immensely appreciative. Thank you!

Okay, let me quickly retract the bit about the *.master loading in Visual Studio. It just occurred to me that I'm not programming against their file type so of course they're going to do whatever they used to do. This is emblematic of the sort of day I'm having. :frowning:

Only a scrap of progress. I've fixed my dunder-headed mistake with Visual Studio, so it'll now launch in an existing window if there is one (rather than always open a new instance of the application.) I'm still getting errors with the Chrome part. If I just pass the filepath & filename, the way my DEV server is configured, the pages simply won't render, hence the clipboard stuff (which Leo was very kind to work up for me in a different thread.)

if InStr(path,"d:\websandbox\trunk") then
	commandLine = vbQuote & "C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" & vbQuote
	commandLine = commandLine & " " & vbQuote & strFilePath & "\" & strFileName & vbQuote
	commandLine = commandLine & " /Edit"
elseif InStr(path,"x:\") then
	commandLine = vbQuote & "C:\Documents and Settings\gbw1\Local Settings\Application Data\Google\Chrome\Application\chrome.exe" & vbQuote
	Clipboard COPYNAMES REGEXP x:\\(.*) http://web-dev-vm/humanservices/\1
	commandLine = commandLine & " " & vbQuote & {clip} & vbQuote
else
	commandLine = vbQuote & home & "dopusrt.exe" & vbQuote & " /cmd filetype open file"
	commandLine = commandLine & " " & vbQuote & strFilePath & "\" & strFileName & vbQuote
end if

shell.Run commandLine

So I must be missing something on how Opus handles file type actions.

I can use the following code off a button just fine, but if I try to use it as the shift-double left-click action it doesn't work (attempts to load only the filename, none of the beginning portion of the URI is present.)

Clipboard COPYNAMES REGEXP D:\\WebSandbox\\trunk\\(.*) http://web-dev-vm/humanservices/\1 REGEXP X:\\(.*) http://web-dev-vm/humanservices/\1
cd "C:\Documents and Settings\gbw1\Local Settings\Application Data\Google\Chrome\Application"
"C:\Documents and Settings\gbw1\Local Settings\Application Data\Google\Chrome\Application\chrome.exe" {clip}

I'll reply a bit more detail later... for now, you can't run regular Opus button or OS shell commands within the VBscript code portion of that button I posted.

With some more research I've wandering into the previously unknown world of the Rename Script functionality. This explains a lot about both my ignorance & why my attempts thus far have failed. Sigh... :blush:

After rooting around the help files & this forum, there was a post from Jon recommending using VBScript's Replace(). Which seems to be working out just fine for me now (I'd been playing around with the initial line with REGEXP but couldn't get it to pass through the filename itself...)

if InStr(path,"d:\websandbox\trunk") then
	commandLine = vbQuote & "C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" & vbQuote
	commandLine = commandLine & " " & vbQuote & strFilePath & "\" & strFileName & vbQuote
	commandLine = commandLine & " /Edit"
elseif InStr(path,"x:\") then
	path = Replace(path,"x:\","http://web-dev-vm/humanservices/")
	commandLine = vbQuote & "C:\Documents and Settings\gbw1\Local Settings\Application Data\Google\Chrome\Application\chrome.exe" & vbQuote
	commandLine = commandLine & " " & vbQuote & path & strFileName & vbQuote
else
	commandLine = vbQuote & home & "dopusrt.exe" & vbQuote & " /cmd filetype open file"
	commandLine = commandLine & " " & vbQuote & strFilePath & "\" & strFileName & vbQuote
end if

shell.Run commandLine

There's probably a more elegant way to do this, but I'll take it for the time being. :smiley: