Make default app depend on location of file?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
kunkel321
Posts: 664
Joined: 10 Jun 2012 03:45
Location: Near Seattle

Make default app depend on location of file?

Post by kunkel321 »

If a PDF is in my /Downloads/ folder, I usually want to open it with Sumatra PDF. If it's a PDF in any other folder though, I usually want to open it with Acrobat. What would be the best way to automate this? Best case scenario would be for this behavior to occur when I double-click a PDF. But maybe this is controlled by Windows (?) A scripted toolbar button, or keyboard command would maybe be okay too. (I do already have both apps set in my Portable App Associations toolbar command). Thoughts?
ste(phen|ve) kunkel
Scaling: Main monitor 125%, Secondary monitor on the right 100%
OS: Win 10. XYplorer version: Latest beta, unless specified.

highend
Posts: 14996
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Make default app depend on location of file?

Post by highend »

A PFA would do it with a minimal script that checks for the folder, like:

Code: Select all

pdf>::if (<pfaitem> LikeI "*\Downloads\*") { run """<path to sumatra.exe>"" ""<pfaitem>"""; } else { run """<path to adobe acrobat.exe>"" ""<pfaitem>"""; }
One of my scripts helped you out? Please donate via Paypal

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Make default app depend on location of file?

Post by TheQwerty »

Personally, it comes down to the number and type of special cases you have.

For the scenario mentioned I'd use two PFAs:

Code: Select all

*\Downloads\*.pdf>sumatra.exe
pdf>acrobat.exe
One advantage to this approach is that in your Downloads folder the open with menu will show both entries allowing you to temporarily use acrobat if desired. Unfortunately, outside of that folder you'll only see the acrobat option unless you also add a third entry:

Code: Select all

*\Downloads\*.pdf>sumatra.exe
pdf>acrobat.exe
pdf>sumatra.exe
Another advantage is it means you don't have to give consideration to how your script works when called with multiple items - which can be a bit confusing.


However, this does not scale well when there are more special cases. For instance if you wanted to apply this same behavior to epub files (ignoring that acrobat cannot handle them). Then you'd need:

Code: Select all

*\Downloads\*.pdf;*\Downloads\*.epub>sumatra.exe
pdf;epub>acrobat.exe
At present there's no good way to consolidate the patterns for sumatra - something similar to Color Filter's pre-filters or regex support would help greatly.


My suggestion is start with multiple PFAs and when the number, length, or complexity annoys you and you have the time convert to a script as highend suggested.

But please put that script in a file and load it from your PFA! :P

Present-me is a huge fan of one-liners but future-me always wants to kill past-me for the nightmares they leave behind! :twisted:

kunkel321
Posts: 664
Joined: 10 Jun 2012 03:45
Location: Near Seattle

Re: Make default app depend on location of file?

Post by kunkel321 »

Thanks for the tips here Guys!

At first I tried regurgitating these into an .xys that I could call from a toolbar button. That failed miserably. :roll:
Then I figured I'd start-over by just pasting Highend's suggestion right into the list of PFA definitions (adding the paths of course). (as a oneliner -- :wink: ) Low and behold it works as expected, but (unexpectedly to me) it also works if I just double-click the PDF file, not even using the PFA list that's on my toolbar! Hooray. :tup:

Interesting note: Neither pfaitem nor LikeI appear to be in the xyplorer help file....
ste(phen|ve) kunkel
Scaling: Main monitor 125%, Secondary monitor on the right 100%
OS: Win 10. XYplorer version: Latest beta, unless specified.

highend
Posts: 14996
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Make default app depend on location of file?

Post by highend »

but (unexpectedly to me) it also works if I just double-click the PDF file
That's because you have:
Open Items by First "Open With..." Match
ticked (right click on the PFA icon for the context menu)
Neither pfaitem nor LikeI appear to be in the xyplorer help file....
Ehem, you should better read it :D

"<pfaitem>" is in Advanced Topics - Portable File Associations (The special variable <pfaitem>)
and
"LikeI" is in Advanced Topics - Scripting - Comparisons...
One of my scripts helped you out? Please donate via Paypal

kunkel321
Posts: 664
Joined: 10 Jun 2012 03:45
Location: Near Seattle

Re: Make default app depend on location of file?

Post by kunkel321 »

highend wrote:
but (unexpectedly to me) it also works if I just double-click the PDF file
That's because you have:
Open Items by First "Open With..." Match
ticked (right click on the PFA icon for the context menu)
Indeed I do!
highend wrote:[...]"<pfaitem>" is in Advanced Topics - Portable File Associations (The special variable <pfaitem>)
and
"LikeI" is in Advanced Topics - Scripting - Comparisons...
Strange... I could've sworn I had used the "Search" feature of the compiled help, and did not find either... I just tried it again though, and was able to find each... I guess I'm just losing it. :oops:
ste(phen|ve) kunkel
Scaling: Main monitor 125%, Secondary monitor on the right 100%
OS: Win 10. XYplorer version: Latest beta, unless specified.

Post Reply