Script to toggle "main contents" font size?

Discuss and share scripts and script files...
ghost zero
Posts: 840
Joined: 26 Apr 2010 17:48

Script to toggle "main contents" font size?

Post by ghost zero »

Can anyone tell me how to make a script to toggle "main contents" font size between default size and size 14? I want to make a button to toggle it.

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

Re: Script to toggle "main contents" font size?

Post by TheQwerty »

The only way to achieve this with purely XY's scripting would be to modify the setting in XYplorer.ini and restart XY - which I'd consider a deal breaker. :?

Either Don needs to be convinced to add commands for the various mouse wheel tricks or a script would need to use another program to send mouse wheel events back to XY.
(Unless I'm wrong and the undocumented and should-never-be-used SendKeys SC can actually do this?)

The latter is definitely possible but I don't have the time to figure it out right now - sorry!
If I remember and no one else offers a solution I'll try to look into it tomorrow. :whistle:

ghost zero
Posts: 840
Joined: 26 Apr 2010 17:48

Re: Script to toggle "main contents" font size?

Post by ghost zero »

doing it via mouse wheel isn't an ideal workaround. perhaps don can add a script command to change font sizes?

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Script to toggle "main contents" font size?

Post by highend »

A rather simple AHK script...

Compile and try it. Maybe you have to play with the Sleep command but 250 msecs should be sufficient.
Tried it with the latest beta version a couple of times and so far it worked flawlessly. I doubt there are any other methods available atm (Don says: don't use sendkeys, it could be removed on any future release...).

Code: Select all

#SingleInstance force
#NoTrayIcon
SendMode Input

Send, {F9}
WinWaitActive, Configuration - XYplorer, 2
if ErrorLevel = 0
{
	Send, mf{Tab}{Enter}{Tab 2}
	Sleep, 250
	ControlGetText, CurFontSize, Edit3, A
	If CurFontSize = 14
		Send, 8
	else
		Send, 14
	Send, {Enter}{Shift down}{Tab}{Shift up}{Enter}
}
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: Script to toggle "main contents" font size?

Post by klownboy »

Hi highend, It shows you what you can do with AHK when you need too. The script worked fine for me too. I had to change the CKS from F9 to alt-F9 since I had reassigned F9 to Dual Pane, but once I did that, it worked fine. Not that I would use it, but I did want to check it out. 8)
Thanks,
ken
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

ghost zero
Posts: 840
Joined: 26 Apr 2010 17:48

Re: Script to toggle "main contents" font size?

Post by ghost zero »

ty for the tip, but i would rather have a button for this on my XY toolbar.

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Script to toggle "main contents" font size?

Post by highend »

@Ken

No problem :)

@ghost zero

And what's the problem with creating a button and call this external command? You (probably) won't get a reliable internal (scripting) solution because... Really, why should anyone switch fonts all the time? If someone is asking for a script command to do that, others will come and ask for a sc that changes background colors... or the title bar template... or the list of previewed formats... or...
One of my scripts helped you out? Please donate via Paypal

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

Re: Script to toggle "main contents" font size?

Post by TheQwerty »

Turns out there is a scriptable way to change the font size by making use of the existing 'Zoom In' and 'Zoom Out' toolbar buttons and the button() SC.

With this knowledge I've created a snippet of a scripted CTB that will toggle between two font sizes.

Note however that strictly speaking this will not toggle between the default size and 14, but rather it will increase/decrease the current size 5 times. So if you use this to toggle to large fonts and then zoom out on your own the next time you press the button it will zoom out even further.

For that reason I've given the button some right-click scripts to quickly access the normal zoom in/out buttons and also to set the state of the button without adjust the font size.

To increase or decrease the difference between the font sizes modify the value of $repeats in the left-click script.


To create this button type and execute the following in the address bar:

Code: Select all

::snippet;
This will open the 'Enter Snippet' dialog, and then copy and paste the following into that dialog:

Code: Select all

Snip: CTB 1
  XYplorer 12.80.0000, 8/7/2013 10:57:55 AM
Action
  NewUserButton
Name
  Toggle Font
Icon
  :zoomin
ScriptL
  "Toggle Font Size"
    // The two states we're toggling,
    // and also the buttons/icons to use.
    $ACTIONS = 'zoomin|zoomout';
  
    // Current State
    $state = CTBState();
  
    // Button to press in this state.
    $button = GetToken($ACTIONS, $state+1, '|');
  
    // Repeatedly call the corresponding button.
    $repeats = 5;
    while ($repeats > 0) {
      $repeats--;
  
      Button($button, 1);  
    }
  
    // Set new state & icon.
    $state = ! $state;
    $button = GetToken($ACTIONS, $state+1, '|');
    CTBIcon(":$button");
    CTBState($state);
ScriptR
  "Zoom In|:zoomin" Button('zoomin', 1);
  "Zoom Out|:zoomout" Button('zoomout', 1);
  "-"
  "Set Button State to Zoomed Out" CTBState(0);CTBIcon(':zoomin');
  "Set Button State to Zoomed In" CTBState(1);CTBIcon(':zoomout');
FireClick
  0
Or alternately copy the snippet and then just execute 'Snippet <clipboard>;' from the address bar.

HTH

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: Script to toggle "main contents" font size?

Post by klownboy »

Hi TheQuerty,

Very nice example of using CTBstate and CTBicon toggling. I wouldn't use the script for it's intended purpose, but I can certainly learn and use it as an example.

This morning I wrote another method to do essentially the same thing, though in mine, a left-click of the CTB increased the font to 14 and a right-click decreased the font back to 8.5. As in highend's script, it used AHK, but used "Send ^{WheelUp}" to send the "control wheel-up/down" functionality of XY. It worked quite well and fast, but it's certainly not as nice as your method and it's not self-contained in XY scripting. I won't bother to post it now. I forgot about the obvious...Buttons!

Thanks for the example,
Ken
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

ghost zero
Posts: 840
Joined: 26 Apr 2010 17:48

Re: Script to toggle "main contents" font size?

Post by ghost zero »

ty for the suggestions. but unfortunately, these workarounds are no good to me. i am only interested in the original concept of this idea--due to it's simplicity and convenience.

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

Re: Script to toggle "main contents" font size?

Post by TheQwerty »

ghost zero wrote:ty for the suggestions. but unfortunately, these workarounds are no good to me. i am only interested in the original concept of this idea--due to it's simplicity and convenience.
Can you please elaborate on why my solution does not work for you?

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

Re: Script to toggle "main contents" font size?

Post by TheQwerty »

klownboy wrote:Very nice example of using CTBstate and CTBicon toggling. I wouldn't use the script for it's intended purpose, but I can certainly learn and use it as an example.
Thanks! Neither would I but I hadn't played with those CTB commands so it was a good chance to do so.

I'm very pleased that the state persists across sessions, so we don't have to deal with figuring out where/how to store that data.
klownboy wrote:This morning I wrote another method to do essentially the same thing, though in mine, a left-click of the CTB increased the font to 14 and a right-click decreased the font back to 8.5. As in highend's script, it used AHK, but used "Send ^{WheelUp}" to send the "control wheel-up/down" functionality of XY.
I also experimented with sending the commands using nircmd, but I wasn't particularly happy with the results - though I do imagine it was similar to, but probably not as nice as, what you and highend achieve in AHK.

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: Script to toggle "main contents" font size?

Post by klownboy »

Hi again TheQuerty,

I've been enjoying the use of the CBTstate as well as CTBicon since it really allows us to get more commands/uses out of both the left and right clicks of a CTB. With the limit of visible CTBs, if I can get more life out of each one, why not, especially if the actions are similar or related. One left-click of a CTB does one action, two quick left-clicks does another action/menu and similarly, two additional actions can be done right-clicking a CTB. And of course, the same CTB can be used for left and right drag and drop. It's easy to lose track of all this functionality though even with detailed labels. :)

Ken
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

ghost zero
Posts: 840
Joined: 26 Apr 2010 17:48

Re: Script to toggle "main contents" font size?

Post by ghost zero »

TheQwerty wrote:
ghost zero wrote:ty for the suggestions. but unfortunately, these workarounds are no good to me. i am only interested in the original concept of this idea--due to it's simplicity and convenience.
Can you please elaborate on why my solution does not work for you?
i would prefer don add a script command to make my original request possible. my original request is simple, consistent, and portable.

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

Re: Script to toggle "main contents" font size?

Post by TheQwerty »

ghost zero wrote:
TheQwerty wrote:
ghost zero wrote:ty for the suggestions. but unfortunately, these workarounds are no good to me. i am only interested in the original concept of this idea--due to it's simplicity and convenience.
Can you please elaborate on why my solution does not work for you?
i would prefer don add a script command to make my original request possible. my original request is simple, consistent, and portable.
That doesn't really answer my question. :?

Your original request was for a script to toggle between font sizes.
There have been two solutions posted to this thread and they are both pretty simple, portable, and achieve the desired result.

Given your last post, your request probably would have been better understood if you had started off asking Don to give you a scripting command rather than asking the community to write you a script. In the very least it would have saved a few of us from wasting our time trying to help you only to be told that our work is "no good." :roll:

Have it your way...

Post Reply