Here's a SOLUTION to add/remove ITALICS/BOLD via KEYBOARD SHORTCUTS

Previous topic - Next topic

Greg P123


Hi -

I got REALLY tired of the multiple mouse clicks to set/remove italics/bold, so I finally wrote a script to do it using keyboard shortcuts.

The script below will allow you to move up/down the font styles of your current font (cycling through Regular, Italics, Bold, etc).  Highlight your text and hit the shortcut -- that's it!

The script will work with Scribus in fullscreen mode or windowed - and on multi-monitor setups.

The script captures two keystrokes to go up/down the font styles (I used F5 and F6).  If you want to use other keystrokes, it's VERY easy to change (I describe how below).  The script will only capture the F5/F6 if Scribus is the active window, otherwise it passes the F5 and F6 through unchanged.

The whole 'intervention' requires just two files, and I'll share them here.  I'm running on Linux Mint, but this approach could be adapted for other OS's.  (If you do that, add your solution here!)

The two files are both located in the 'Home' folder (easy to find and work with).  They are '.xbindkeys' (to capture the keystrokes and call the script), and 'scribus_font_change.sh' (the script that does the work).  There is only one script because it gets called with a '1' or '2' parameter, depending on whether you want to go up or down the font styles.

Description of Method:

When I am editing text, I always have my Text Properties open on the right (and full height).  This means that the little arrow that activates the dropdown is always in the SAME POSITION relative to the top left right corner of the Scribus window.  This allows me to tell the script to 'click the mouse' on that dropdown arrow, go up/down using an arrow key, then hit 'Enter'.  Voila!

For my setup, the little dropdown arrow is 12 pixels to the left and 120 pixels below the top-right corner of the Scribus screen.  IF YOUR SETUP IS SLIGHTLY DIFFERENT, it's easy to adjust - just change the text of the script in one place.

First, capture the keystrokes:
Go to your Home folder, edit '.xbindkeys' and add these lines:

-----------------

"bash ~/scribus_font_change.sh 1"
   F5

"bash ~/scribus_font_change.sh 2"
   F6

-----------------

Next, create a file called 'scribus_font_change.sh' in the Home folder, add the lines below, and make the file executable.

-----------------

#!/bin/bash

# Check if a parameter is provided
if [ -z "$1" ]; then
  echo "Usage: $0 <parameter>"
  exit 1
fi

# Function to get the window ID under the mouse cursor
get_window_under_mouse() {
    xdotool getmouselocation --shell | grep WINDOW | sed 's/WINDOW=//'
}

# Function to click at a position relative to the window
click_at_position() {
    local window_id=$1
   
    # Get detailed window information
    win_info=$(xwininfo -id $window_id)
   
    # Extract window position and size
    X=$(echo "$win_info" | grep 'Absolute upper-left X' | awk '{print $NF}')
    Y=$(echo "$win_info" | grep 'Absolute upper-left Y' | awk '{print $NF}')
    WIDTH=$(echo "$win_info" | grep 'Width' | awk '{print $NF}')
   
    # Calculate click position relative to top-right corner
    click_x=$((X + WIDTH - 12))
    click_y=$((Y + 120))
   
    # Store current mouse position
    current_mouse=$(xdotool getmouselocation --shell)
    eval "$current_mouse"
   
    # Move mouse to calculated position and click
    xdotool mousemove $click_x $click_y click 1
   
    # Restore mouse position
    xdotool mousemove $X $Y
}

# Get the window ID under the mouse
WINDOW_ID=$(get_window_under_mouse)

# Check if Scribus is active or under the cursor
ACTIVE_WINDOW=$(xdotool getactivewindow getwindowname)
WINDOW_NAME=$(xdotool getwindowname $WINDOW_ID)

if [[ "$ACTIVE_WINDOW" == *"Scribus"* || "$WINDOW_NAME" == *"Scribus"* ]]; then
    # Perform actions based on the parameter
    case $1 in
        1)
            click_at_position $WINDOW_ID
            sleep 0.1
            xdotool key Up key Return
            ;;
        2)
            click_at_position $WINDOW_ID
            sleep 0.1
            xdotool key Down key Return
            ;;
        *)
            echo "Invalid parameter. Use 1 or 2."
            exit 1
            ;;
    esac
else
    # If not in Scribus, pass F5 for parameter 1 or F6 for parameter 2
    if [ "$1" -eq 1 ]; then
        xdotool key F5
    elif [ "$1" -eq 2 ]; then
        xdotool key F6
    fi
fi

-----------------

If you want to use keys other than F5/F6, then change the text that you add to '.xbindkeys' and the F5/F6 that appears at the very end of the script.

(You'll need to reset xbindkeys after any change to make the key capture active.)

If your screen setup is slightly different than mine, you may need to figure out where to 'mouse click' relative to the top-right corner (below the maximize button) - and change the offsets in the script (read the comments - it's easy to figure out).

Big thanks to Grok for it's help!  :)

I hope you enjoy.  It works GREAT over here.

- Greg

Juliansegovia

#1
Scribus has its internal python scripting facility. Have you tried that development path? The reason I asked is that I am looking for a solution to your same problem but though an approach that will not involve navigating the screen but through Scribus internals. Unfortunately, I'm still searching.

This is quite frustrating for me because bold and italics are supposed to be basic rich text manipulations that merits a very simple keyboard strokes like <Ctrl-B> and <Ctrl-I> as in most richtext editors.

If you have tried the python way and concluded that it's impossible, please let me know so I can abandon the thought.