Make default app depend on location of file?
-
kunkel321
- Posts: 664
- Joined: 10 Jun 2012 03:45
- Location: Near Seattle
Make default app depend on location of file?
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.
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?
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?
Personally, it comes down to the number and type of special cases you have.
For the scenario mentioned I'd use two PFAs: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: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: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!
Present-me is a huge fan of one-liners but future-me always wants to kill past-me for the nightmares they leave behind!
For the scenario mentioned I'd use two PFAs:
Code: Select all
*\Downloads\*.pdf>sumatra.exe
pdf>acrobat.exeCode: Select all
*\Downloads\*.pdf>sumatra.exe
pdf>acrobat.exe
pdf>sumatra.exeHowever, 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.exeMy 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!
Present-me is a huge fan of one-liners but future-me always wants to kill past-me for the nightmares they leave behind!
-
kunkel321
- Posts: 664
- Joined: 10 Jun 2012 03:45
- Location: Near Seattle
Re: Make default app depend on location of file?
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.
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 --
) 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. 
Interesting note: Neither pfaitem nor LikeI appear to be in the xyplorer help file....
At first I tried regurgitating these into an .xys that I could call from a toolbar button. That failed miserably.
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 --
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.
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?
That's because you have:but (unexpectedly to me) it also works if I just double-click the PDF file
Open Items by First "Open With..." Match
ticked (right click on the PFA icon for the context menu)
Ehem, you should better read itNeither pfaitem nor LikeI appear to be in the xyplorer help file....
"<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?
Indeed I do!highend wrote:That's because you have:but (unexpectedly to me) it also works if I just double-click the PDF file
Open Items by First "Open With..." Match
ticked (right click on the PFA icon for the context menu)
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.highend wrote:[...]"<pfaitem>" is in Advanced Topics - Portable File Associations (The special variable <pfaitem>)
and
"LikeI" is in Advanced Topics - Scripting - Comparisons...
ste(phen|ve) kunkel
Scaling: Main monitor 125%, Secondary monitor on the right 100%
OS: Win 10. XYplorer version: Latest beta, unless specified.
Scaling: Main monitor 125%, Secondary monitor on the right 100%
OS: Win 10. XYplorer version: Latest beta, unless specified.
XYplorer Beta Club