wmctrl is a command-line tool that allows you to interact with the X Window System, providing the ability to control the position, size, state, and other properties of windows on the desktop.
The command you've provided uses wmctrl with certain options to manipulate a window belonging to Skype for Linux:
-r 'skypeforlinux': This option specifies the window to be targeted. The argument 'skypeforlinux' is expected to match the window title or a substring of it. If skypeforlinux does not uniquely identify the window, the command may not work as expected. If the actual window title is different, you'll need to adjust this part of the command to match the title.
-b add,maximized_vert,maximized_horz: This option dictates the action to be performed on the window. The add action specifies that the following states should be added to the window. maximized_vert and maximized_horz are the states to be added, and they stand for vertical and horizontal maximization, respectively. When both are used together, they effectively maximize the window on the screen.
Before running the command, make sure you have wmctrl installed on your system. It's usually available in the repositories of most Linux distributions, and you can install it using your package manager (e.g., sudo apt-get install wmctrl on Debian/Ubuntu-based distributions).
This should find the Skype for Linux window and maximize it both vertically and horizontally, assuming the title matches. If the title does not match exactly, you can use the -l option with wmctrl (e.g., wmctrl -l) to list all windows and their titles, so you can find the exact title of the Skype window.
Remember that the command is case-sensitive and that it might also require the title to be fully matched, depending on the options and the version of wmctrl you are using. If you still experience issues, try using a more specific title or a different matching pattern.
User
I've added that line to this file. Would it work? #!/bin/sh
Based on the context of the script you've provided, there are a few things to consider for the final line involving wmctrl to work as expected:
Desktop Environment Ready: The wmctrl command requires a desktop environment to be running with a window manager that adheres to the Extended Window Manager Hints (EWMH) specification. Make sure that the desktop environment is fully initialized and running before this line is executed. It may not work properly if it's run too early in the startup process before the desktop is ready.
Correct Window Title: The provided wmctrl command will attempt to maximize the window with the title 'Mozilla Firefox'. Ensure that the title of the Firefox window actually matches this string. If the title is different due to customization or version differences, adjust the string to match the actual title of the Firefox window.
Application Startup Delay: When an application like Firefox is started, it may take a moment for the window to appear. If you run the wmctrl command immediately after starting Firefox without a delay, the window might not be found, and the command could fail. To address this, you could implement a delay or loop to wait for the window to appear.
Background Execution: You are starting Skype with the su - guest -c "skypeforlinux" command. This could potentially block execution of subsequent commands if Skype does not run in the background. Since you are not appending an & to run Skype in the background, it's important that Skype itself daemonizes (forks to the background), or else it will block the script.
Here's a revised portion of the script with some improvements:
sh
su - guest -c "skypeforlinux &" # Run Skype in the background
sleep 5 # Wait for 5 seconds to allow Skype to launch properly
firefox & # Start Firefox in the background
sleep 5 # Wait for 5 seconds to allow Firefox to launch properly
# Loop until the Firefox window appears
until wmctrl -r 'Mozilla Firefox' -b add,maximized_vert,maximized_horz; do
sleep 1 # Wait before trying again
done
sync
In this revised script:
Skype is started in the background using &, which allows the script to continue executing without waiting for Skype to close.
User
Sorry, I wanted to use this: rm -rf /home/guest /tmp/*; cp -a /opt/scripts/guest /home; sync
# Session manager:
#/opt/scripts/session-manager
# Bottom panel:
#/opt/scripts/start-panel
su - guest -c "skypeforlinux"
sleep 10
wmctrl -r 'skypeforlinux' -b add,maximized_vert,maximized_horz
sync
Assistant
Your updated script will now execute skypeforlinux as the user 'guest', wait for 10 seconds to give Skype time to start and create its window, and then use wmctrl to maximize the Skype window. Here's a structured explanation:
rm -rf /home/guest /tmp/*; will forcefully remove the /home/guest directory and everything within /tmp/.
cp -a /opt/scripts/guest /home; will copy a directory /opt/scripts/guest into /home, creating /home/guest.
sync; will flush file system buffers, forcing changed blocks to disk, which ensures that the copy operation is finished and the data is safely stored on disk before proceeding.
su - guest -c "skypeforlinux" switches user context to 'guest', then executes Skype for Linux. This is presumably where you want Skype to start running.
sleep 10 introduces a delay of 10 seconds. This is meant to give Skype enough time to launch and create its window.
wmctrl -r 'skypeforlinux' -b add,maximized_vert,maximized_horz uses wmctrl to find a window with the title 'skypeforlinux' and maximizes it both vertically and horizontally.
Another sync; makes sure any changes are written to disk.
A couple of things to note:
Make sure that 'skypeforlinux' is the correct window title. If the window title is something else, you need to replace 'skypeforlinux' with the correct title. Use wmctrl -l to list window titles if you aren't sure.
Running Skype as the user 'guest' should work fine as long as 'guest' has the necessary permissions and configuration to run the application properly.
As previously mentioned, the sleep duration may need to be adjusted. Depending on the system speed and how quickly Skype starts, 10 seconds may or may not be sufficient.
Be careful with rm -rf /home/guest /tmp/*, as this will delete all data in those directories, which could include important or unsaved files.
With all this, your script should start Skype maximized, but remember to test it thoroughly to ensure that all steps work as intended in your kiosk environment.
User
What do you think about this? Is there any error? #!/bin/sh
Disable backup of the /home folder (just in case the session is restarted):
sed -i 's_^cp -a /home/guest_#cp -a /home/guest_g' /etc/xdg/openbox/autostart
Start application in a loop:
rm -rf /home/guest /tmp/*; cp -a /opt/scripts/guest /home; sync
# Session manager:
#/opt/scripts/session-manager
# Bottom panel:
#/opt/scripts/start-panel
su - guest -c "skypeforlinux"
sleep 10
sync
while true; do
wmctrl -r 'skypeforlinux' -b add,maximized_vert,maximized_horz
done
sync
Assistant
The script appears to be designed to prepare a kiosk environment and ensure that Skype for Linux runs in a maximized window. Here are a few observations and suggestions regarding the script you provided:
The rm -rf /home/guest /tmp/*; command is very destructive as it forcefully removes the entire /home/guest directory and everything in the /tmp directory. Ensure that this operation is intentional and that there's no important data in these directories that need to be preserved.
The cp -a /opt/scripts/guest /home; command copies a pre-configured directory (guest) to the /home directory. Running sync after this line ensures that the filesystem buffers are flushed to disk which is good practice after copying files.
The su - guest -c "skypeforlinux" command executes Skype as the 'guest' user. The sleep 10 command waits for 10 seconds, presumably to give Skype enough time to initiate before attempting window manipulation.
After another sync command to flush the filesystem buffers, you enter a while true loop that continuously runs wmctrl -r 'skypeforlinux' -b add,maximized_vert,maximized_horz. This loop, as currently written, will try to maximize the Skype window in very rapid succession indefinitely, without any delay between attempts. This could have performance implications and may not be necessary because usually, once a window is maximized, it doesn't need to be maximized again.
Another consideration is that Skype might change its window title once it has fully launched, or if a chat window is opened, making the wmctrl -r 'skypeforlinux' command not able to find the window anymore. You might want to ensure that the title you're matching remains constant or find a way to match it reliably regardless of the state of the Skype application.
Here is a slightly revised version of the script that includes a delay in the while loop and breaks out of the loop once Skype is successfully maximized:
Disable backup of the /home folder (just in case the session is restarted):
sed -i 's_^cp -a /home/guest_#cp -a /home/guest_g' /etc/xdg/openbox/autostart
Start application in a loop:
rm -rf /home/guest /tmp/*; cp -a /opt/scripts/guest /home; sync
# Session manager:
#/opt/scripts/session-manager
# Bottom panel:
#/opt/scripts/start-panel
su - guest -c "skypeforlinux"
sleep 10
sync
while true; do
wmctrl -r 'skypeforlinux' -b add,maximized_vert,maximized_horz
sleep 60
done
sync
Assistant
The revised script now includes a sleep 60 command within the loop, which introduces a 60-second delay between attempts to maximize the Skype window. This is certainly an improvement over the previous version of the script, as it reduces the system load by not continuously attempting to maximize the window with no delay between tries.
However, there are a couple of additional points to consider:
In most cases, once a window is maximized, it should remain maximized unless the user or some other process changes its state. You typically don't need to keep trying to maximize the window every minute. If you're facing an issue that requires the window to be maximized repeatedly, it might be worth investigating the underlying cause of why the window isn't staying maximized.
The script doesn't check for successful maximization before continuing the loop. This could lead to unnecessary commands being executed. You might want to add a check as I included in the previous example. If the Skype window title might change throughout the session (e.g., when a new message comes in), you should also handle the possibility that the title used in the wmctrl -r 'skypeforlinux' command no longer matches.
There is a risk with rm -rf /home/guest /tmp/* since it's removing directories forcefully and without confirmation. It's important to ensure that this is the desired behavior and that no critical data is being lost.
It's not clear what the comments referring to the session manager and the bottom panel scripts are for since these lines are commented out. If these scripts are part of the kiosk environment setup, consider whether they should be included and uncommented.
Given these considerations, the revised script should lead to a more stable system load than the previous version, but it may still include unnecessary operations unless it is certain that something could interfere with the maximized state of the Skype window.
User
What is "fi" in your version?
Assistant
In shell scripting, fi is used to denote the end of a conditional block that starts with if. The if statement is used to execute commands based on the evaluation of a conditional expression. In a script, every if block must be closed with a corresponding fi.
Here’s the general syntax of an if statement in shell scripting:
sh
if [ condition ]; then
# commands to execute if the condition is true
else
# commands to execute if the condition is false (else is optional)
fi # End of the if statement
In the version of the script where I used fi, it is part of an if construct that checks whether the wmctrl command was successful. If wmctrl successfully finds and maximizes the Skype window, it breaks out of the while loop. If not, it waits for 2 seconds before trying again.
Here is the relevant section of the script with the if statement and its corresponding fi:
sh
while true; do
if wmctrl -r 'skypeforlinux' -b add,maximized_vert,maximized_horz; then
echo "Skype window maximized successfully."
break # Exit the loop once the window is maximized
else
echo "Waiting for Skype window..."
sleep 2 # Wait for 2 seconds before trying again
fi # End of the if statement
done
In this context, the if block is checking the exit status of the wmctrl command. If the command exits with a status of 0 (indicating success), the echo statement prints a success message, and the break command exits the loop. If the command exits with a non-zero status (indicating failure), the script prints a waiting message and sleeps for 2 seconds before reiterating the loop. The fi marks the end of this conditional logic.
Not yet included in a published release.
Firefox is also started in the background, allowing the script to continue.
A sleep command is added to provide a 5-second delay, giving the applications time to start and create their windows.
An until loop is used to continually attempt to maximize the Firefox window until successful.
Please adjust the sleep values and the window titles as necessary for your environment.
#!/bin/sh
#
# Start kiosk application in a loop.
# Author: T.Jokiel <http://porteus-kiosk.org>
# Disable backup of the /home folder (just in case the session is restarted):
sed -i 's_^cp -a /home/guest_#cp -a /home/guest_g' /etc/xdg/openbox/autostart
# Start application in a loop:
rm -rf /home/guest /tmp/*; cp -a /opt/scripts/guest /home; sync
# Session manager:
#/opt/scripts/session-manager
# Bottom panel:
#/opt/scripts/start-panel
su - guest -c "skypeforlinux"
sleep 10
sync
# Attempt to maximize the Skype window until successful
while true; do
if wmctrl -r 'skypeforlinux' -b add,maximized_vert,maximized_horz; then
echo "Skype window maximized successfully."
break # Exit the loop once the window is maximized
else
echo "Waiting for Skype window..."
sleep 2 # Wait for 2 seconds before trying again
fi
done
sync
Please adjust the matching title ('skypeforlinux') as necessary, and consider whether running wmctrl in such a loop is actually needed after the initial maximization.