How can I disable a windows's resize action in X window system? - xlib

I am trying to use xprop to set a window's allowed actions,for example,I want to make a resizeable window become unresizeable by the following command.
xprop -id "0x04400015" -format _NET_WM_ALLOWED_ACTIONS 32a -set _NET_WM_ALLOWED_ACTIONS " _NET_WM_ACTION_FULLSCREEN, _NET_WM_ACTION_MINIMIZE, _NET_WM_ACTION_SHADE, _NET_WM_ACTION_MAXIMIZE_HORZ, _NET_WM_ACTION_MAXIMIZE_VERT, _NET_WM_ACTION_CHANGE_DESKTOP, _NET_WM_ACTION_ABOVE, _NET_WM_ACTION_BELOW"
I remove the action "_NET_WM_ACTION_RESIZE" in _NET_WM_ALLOWED_ACTIONS ,But the window can still be resized.
Is there anything wrong? And are there any other ways to make it?

Related

gnuplot under windows: how to specify window size/position when it startup?

Under windows 10, how can I specify window postion (X,Y) and window size (width,height) of gnuplot, via command line arguments?
The path of the application is
D:\gnuplot\bin\wgnuplot.exe
how can specify window postion and size with it? like with cygwin mintty:
D:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico
-p 372,12 -s 135,50 -o Font=Consolas -o FontHeight=13 -
show version long output
Version 5.2 patchlevel 0 last modified 2017-09-01
Compile options:
+READLINE -LIBREADLINE +HISTORY
-BACKWARDS_COMPATIBILITY +UNICODE +OBJECTS +STATS +EXTERNAL_FUNCTIONS
+LIBCERF +GD_PNG +GD_JPEG +GD_TTF +GD_GIF +ANIMATION
-USE_CWDRC +USE_MOUSE +HIDDEN3D_QUADTREE
MAX_PARALLEL_AXES=13
P.S.
I mean the window of gnuplot, not the graph it plots.
Gnuplot under Windows 10 can use an init file wgnuplot.ini which is located at %AppData% (C:\Users\maij\AppData\Roaming in my case).
You can generate and update the file by clicking the upper left icon of the gnuplot window and following "Options -> Update wgnuplot.ini" (see the following picture). Please play a bit with window positions and sizes and updating the ini file to see how it works.
My suggestion would be to generate wgnuplot.ini with the appropriate entries before launching gnuplot.
Currently my wgnuplot.ini looks as follows:
[WGNUPLOT]
TextOrigin=290 50
TextSize=785 489
TextMinimized=0
TextMaximized=0
TextFont=Consolas,9
TextWrap=1
TextLines=400
SysColors=0
DockVerticalTextFrac=350
DockHorizontalTextFrac=400
TextOrigin and TextSize are the options you are interested in.

Ghostscript changed Orientation from landscape to portrait

I have a PDF file that I need to change the orientation from landscape to portrait, using this command GS. The Orientation switch it is not changing the orientation. Is there a extra setting I need to add?
::Path to your Ghostscript EXE
set GSC="C:\Program Files (x86)\gs\gs9.16\bin\gswin32.exe"
%GSC% -sDEVICE=pdfwrite -sOutputFile="D:\TRANS\PDF\2_ZNOR_00000000000000000070.pdf" -dNOPAUSE -dEPSCrop -c "<</Orientation 3>> setpagedevice" -f "D:\TRANS\PDF\1_ZNOR_00000000000000000070.pdf"
It worked for me
List<string> switches = new List<string>
{
"-empty",
"-dQUIET",
"-dSAFER",
"-dBATCH",
"-dNOPAUSE",
"-dNOPROMPT",
"-dDEVICEHEIGHTPOINTS=612",
"-dDEVICEWIDTHPOINTS=792",
"-dFIXEDMEDIA",
"-dFitPage",
"-sDEVICE=pdfwrite",
"-dAutoRotatePages=/None",
"-sOutputFile=" + resultFilePath,
"-c",
"<</Orientation 1>> setpagedevice",
"-f"
};
switches.Add(this.FilePath);
Most of the switches you are using there will have no effect at all, and you haven't done anything to rotate the PDF file either.
The first thing to note is that Ghostscript is really the wrong tool for this job, it doesn't modify PDF files, it generates completely new ones. The process is described here
The -dEPSCrop switch only has an effect if the input is an EPS file, otherwise it does nothing.
The operands to setpagedevice are incorrect, you are passing an empty hex string <> when setpagedevice expects a dictionary <<>>. Even then an empty dictionary will do nothing.
I expect you intended to put <</Orientation 1>> setpagedevice but actually that's only a media matching request. In order to get Ghostscript to create a rotated PDF file you would have to alter the media size, set it to fixed, and set -dFitPage. You would also have to set the AutoRotatePages switch to None in order to prevent the automatic reorientation of the output so that the text is horizontal.
Since you haven't supplied the PDF file to look at, nor stated its media size, I can only guess at the sizes. However, something like
gswin32c.exe -sDEVICE=pdfwrite -sOutputFile=new.pdf -dDEVICEHEIGHTPOINTS=612 -dDEVICEWIDTHPOINTS=792 -dFitPage -dAutoRotatePages=/None input.pdf

Retina display: How to display images in native pixel resolution in Finder and Preview

This is a pseudo question to share my own trick and script below.
The point is to be able to display image pixel for pixel on Retina displays. This is mainly useful for high resolution image and/or for developers working on HDPI version of images.
The solution works well only if the display setting is set to 2:1 ratio in the OS X preferences. Beware, late 2016 MacBook Pro default setting is not set to 2:1 by default. You should set it on the medium setting to get it right.
Finder : the simple trick is to give a name ending with #2x (before the extension): my_image#2x.jpg . Then when using Quick Look feature the image is pixel-wise. As this naming scheme is recommended for retina images, both normal and HDPI images display at same size, as expected, the retina being sharper.
Preview : In preview, the DPI resolution of an image is interpreted as normal if it is set to 72dpi. By setting it to 144, you get the right display ratio. One can achieve the same effect at 72dpi by changing the display scale to 50%, but the scale setting does not stick to the image file while the DPI setting does. Change it through the Tools->Size menu item.
Here below is a small applescript to automate 144dpi setting from the Finder.
tell application "Finder"
repeat with item_cour in selection as list
if word 1 of (the kind of item_cour as text) is "Image" then
set path_cour to POSIX path of (item_cour as text)
do shell script "p_cour='" & path_cour & "';
tags=$(xattr -px com.apple.metadata:_kMDItemUserTags \"$p_cour\");
f_info=$(xattr -px com.apple.FinderInfo \"$p_cour\");
sips -s dpiHeight 144 -s dpiWidth 144 \"$p_cour\";
xattr -wx com.apple.FinderInfo '$f_info' \"$p_cour\";
xattr -wx com.apple.metadata:_kMDItemUserTags \"$tags\" \"$p_cour\" "
-- do shell script "convert \"" & path_cour & "\" -set units PixelsPerInch -density 144 \"" & path_cour & "\""
end if
end repeat
end tell
Since the sips command does not preserve tags, the script includes 4 lines to get and set them back to the file after it has been modified, using the xattr command.
To install the script: open the script editor, create a new document, paste the code and save it into the ~/Library/Scripts/Finder folder.
Be sure to check the Show the Script Menu option in Script editor preference.
To use the script: select image file(s) in Finder and activate the script from the menu.

Determine OS X keyboard layout ("input source") in the terminal/a script?

I would like to determine the OS X keyboard layout (or "input source" as OS X calls it) from the terminal so that I can show it in places like the tmux status bar.
So I want to know if the current layout is "U.S." or "Swedish - Pro" for example.
Googling turns up nothing for me. Is this possible?
Note: #MarkSetchell deserves credit for coming up with the fundamental approach - where to [start to] look and what tools to use.
After further investigation and back and forth in the comments I thought I'd summarize the solution (as of OS X 10.9.1):
do shell script "defaults read ~/Library/Preferences/com.apple.HIToolbox.plist \\
AppleSelectedInputSources | \\
egrep -w 'KeyboardLayout Name' | sed -E 's/^.+ = \"?([^\"]+)\"?;$/\\1/'"
Note how \ is escaped as \\ for the benefit of AppleScript, which ensures that just \ reaches the shell. If you want to execute the same command directly from the shell (as one line), it would be:
defaults read ~/Library/Preferences/com.apple.HIToolbox.plist AppleSelectedInputSources | egrep -w 'KeyboardLayout Name' |sed -E 's/^.+ = \"?([^\"]+)\"?;$/\1/'
The currently selected keyboard layout is stored in the user-level file ~/Library/Preferences/com.apple.HIToolbox.plist, top-level key AppleSelectedInputSources, subkey KeyboardLayout Name.
defaults read ensures that the current settings are read (sadly, as of OSX 10.9, the otherwise superior /usr/libexec/PlistBuddy sees only a cached version, which may be out of sync).
Since defaults read cannot return an individual key's value, the value of interest must be extracted via egrep and sed - one caveat there is that defaults read conditionally uses double quotes around key names and string values, depending on whether they are a single word (without punctuation) or not.
Update:
Turns out that AppleScript itself can parse property lists, but it's a bit like pulling teeth.
Also, incredibly, the potentially-not-fully-current-values problem also affects AppleScript's parsing.
Below is an AppleScript handler that gets the current keyboard layout; it uses a do shell script-based workaround to ensure that the plist file is current, but otherwise uses AppleScript's property-list features, via the Property List Suite of application System Events.
Note: Obviously, the above shell-based approach is much shorter in this case, but the code below demonstrates general techniques for working with property lists.
# Example call.
set activeKbdLayout to my getActiveKeyboardLayout() # ->, e.g., "U.S."
on getActiveKeyboardLayout()
# Surprisingly, using POSIX-style paths (even with '~') works with
# the `property list file` type.
set plistPath to "~/Library/Preferences/com.apple.HIToolbox.plist"
# !! First, ensure that the plist cache is flushed and that the
# !! *.plist file contains the current value; simply executing
# !! `default read` against the file - even with a dummy
# !! key - does that.
try
do shell script "defaults read " & plistPath & " dummy"
end try
tell application "System Events"
repeat with pli in property list items of ¬
property list item "AppleSelectedInputSources" of ¬
property list file plistPath
# Look for (first) entry with key "KeyboardLayout Name" and return
# its value.
# Note: Not all entries may have a 'KeyboardLayout Name' key,
# so we must ignore errors.
try
return value of property list item "KeyboardLayout Name" of pli
end try
end repeat
end tell
end getActiveKeyboardLayout
Recently I had written a small console utility (https://github.com/myshov/xkbswitch-macosx) on Objective-C to do this. It's a lot faster than a script based solutions. It can to get the current input layout but also it can to set the given input layout.
To get a current layout:
$xkbswitch -ge
> US
To set a given layout:
$xkbswith -se Russian
I am not sure of this answer, but it may be worth checking out. If you look in file:
/Library/Preferences/com.apple.HIToolbox.plist
there is a variable called
AppleCurrentKeyboardLayoutSourceID
and mine is set to "British" and I am in Britain...
You can read the file in a script with:
defaults read /Library/Preferences/com.apple.HIToolbox.plist AppleEnabledInputSources
sample output below:
(
{
InputSourceKind = "Keyboard Layout";
"KeyboardLayout ID" = 2;
"KeyboardLayout Name" = British;
}
)
So, I guess your question can be simply answered using this:
#!/bin/bash
defaults read /Library/Preferences/com.apple.HIToolbox.plist AppleEnabledInputSources | grep -sq Swedish
[[ $? -eq 0 ]] && echo Swedish
This question led to the creation of the keyboardSwitcher CLI Tool:
https://github.com/Lutzifer/keyboardSwitcher
Though similar to the already mentioned https://github.com/myshov/xkbswitch-macosx this has additional features, e.g. the list of Layouts is not hardcoded and thus can also support third party layouts (e.g. Logitech) and supports installation via homebrew.
Figured out how to do it with AppleScript, assuming you have the menu bar input menu.
Run this in a terminal:
osascript -e 'tell application "System Events" to tell process "SystemUIServer" to get the value of the first menu bar item of menu bar 1 whose description is "text input"'
Works fine even if you only show the input menu as flag icons, without the input source name.
Mavericks will probably prompt you to allow access, the first time. In earlier versions of OS X I suspect you'll need to turn on support for assistive devices in your accessibility preferences.
I was searching for an answer to an issue I was having with the keyboard layout that lead me to this post. I found the solution for my problem here.
Resolved Issues
You might experience difficulty logging into your account because the keyboard layout may change unexpectedly at the
Login window. (40821875)
Workaround: Log in to your account, launch Terminal, and execute the
following command:
sudo rm -rf /var/db/securityagent/Library/Preferences/com.apple.HIToolbox.plist
This is an Apple official release note for Mojave

call notify balloon message in windows 7 from cmd?

I need to create a notification balloon message in Windows 7 from the Command prompt with custom text. I have searched Google and found shell32.
Notifu is a free open source Windows program that makes balloons appear in the systray with custom text you specify. You can run it from the command-line, so it's easy to include it in a scheduled task or batch file.
http://www.paralint.com/projects/notifu/download.html#Download
This can be done in Powershell:
throw an icon (.ico file) in a c:\temp directory or point that somewhere else.
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$objBalloon = New-Object System.Windows.Forms.NotifyIcon
$objBalloon.Icon = "C:\temp\Folder.ico"
# You can use the value Info, Warning, Error
$objBalloon.BalloonTipIcon = "Info"
# Put what you want to say here for the Start of the process
$objBalloon.BalloonTipTitle = "Begin Title"
$objBalloon.BalloonTipText = "Begin Message"
$objBalloon.Visible = $True
$objBalloon.ShowBalloonTip(10000)
Do some work
Put what you want to say here for the completion of the process
$objBalloon.BalloonTipTitle = "End Title"
$objBalloon.BalloonTipText = "End Message"
$objBalloon.Visible = $True
$objBalloon.ShowBalloonTip(10000)
Here is a working compressed call to powershell. Every part of it is important, because it needs basic notification icon, and "visible" flag.
powershell [Reflection.Assembly]::LoadWithPartialName("""System.Windows.Forms""");$obj=New-Object Windows.Forms.NotifyIcon;$obj.Icon = [drawing.icon]::ExtractAssociatedIcon($PSHOME + """\powershell.exe""");$obj.Visible = $True;$obj.ShowBalloonTip(100000, """TITLE""","""NOTIFICATION""",2)>nul
You may use NirCmd by Nir Sofer like this:
NirCmd.exe trayballoon [Title] [Balloon Text] [Icon File] [Timeout]
This does not seem to work for Windows 10. There you may use Toast.exe, which writes to the message area instead.
Toast.exe -t "Title text" -m "Message" -p NotificationImage.png
You have to turn on notifications for Toast.exe in the Windows 10 settings dialog
under Settings > Notifications & Actions

Resources