How can i find all windows with a particular _NET_WM_NAME? - x11

I need to set a custom property for all windows which have a particular window name.
I tried to first list all windows with the particular name and the problem i faced was that xprop or xwininfo would only list me details for one instance of that window inspite of multiple windows with the same name being available.
xprop -name 'xyz'
xwininfo -name 'xyz'
Eventually i will be using the below command to set the custom property
xprop -name 'xyz' -f Onkar 8s -set Onkar Hello
Another thing to note is that i dont have access to wmctrl or xdotool

Here is a programmatic approach (in C) :
First, get the window IDs using _NET_CLIENT_LIST property using Atoms and XGetWindowProperty().
Then get the window names using WM_NAME under Atoms, again using XGetWindowProperty(). Now you have the list of all active windows in your system, so you can use strcmp() to check the desired name of the window.
The working code is given here:
https://cboard.cprogramming.com/linux-programming/125534-accessing-windows-x11.html
About XGetWindowProperty()
https://tronche.com/gui/x/xlib/window-information/XGetWindowProperty.html
About Atoms:
https://tronche.com/gui/x/xlib/window-information/properties-and-atoms.html

Related

How to show all the available options for a PowerShell command?

For example, this command:
get-netadapter -name "WI-FI"
shows my WIFI network adapter's details with 5 columns of information about it.
but if i do this:
(get-netadapter -name "WI-FI").
and then press tab, I can see a whole lot more information about it that show up after the dot.
now this is only a simple example, there are many more commands like that which by default only show a few columns of information.
what is the universal way of showing all of the available information for each command, like all of the available commands that go after the . in the example above and with their output? I want to show them in console in a nice way like with ft -wrap if possible so I can quickly get a general idea of what information is accessible to me to work with.
I use latest version of PowerShell (7.4 preview) and Windows 11
p.s sometimes pressing tab doesn't work, like in this example:
(get-bitlockervolume -MountPoint $env:SystemDrive).
but we can still use ProtectionStatus after the dot
I usually use command | gm (gm is an alias for Get-Member).
In your case you could type get-netadapter -name "WI-FI" | gm. This returns to you the name, the methods, and properties of the returning object.
To output all properties with values: get-netadapter "WI-FI" | Format-List *

Windows PowerShell default open location

I have been googling and trying different options but I didn't really find anything useful or that worked.
My question is how to set default open location for windows PowerShell, I want it to always open c:/programming/ folder when I start it from like start menu, instead what it opens now.
I'm using windows 10.
Thnx for help
the usual way to tell PoSh where to start up at is to add a Set-Location line to one of your powershell profile files. i added ...
Set-Location D:\Data\Scripts
... to my CurrentUserCurrentHost file. you can learn more about profiles with ...
Get-Help about_Profiles
you can find your version of the profile i used thus ...
$profile |
Select-Object -Property *
please note that none of these files exist by default. you will likely need to make one. if you do be sure it is a plain text file, not a .doc file! [grin]

Get list of open files (descriptors) in OS X

I would like to get a list of open files in a process on os x (10.9.1). In Linux I was able to get this from /proc/PID/fd. However I'm not sure how to get the same on OS X. I found that the procfs is not present on the OS X (by default. possible implementations present, but I do not want to go that way).
So how do I get (natively) the list of open files in a process on OS X. One way is lsof. is there any other support available? please let me know where I can get more info on this.
Thanks.
I had a hard time getting Activity Monitor to show open files for a process that was running as root (via sudo). The original question mentions lsof, and it does the trick exactly. If you know the process name or PID, it's super quick.
Find processes by name:
lsof -c processname
Find processes by PID:
lsof -p 123
(Prefix with sudo as needed, such as if you are not the owner of the process.)
At least on OSX 10.10 (Yosemite, didn't check on Mavericks), you can get the list of open files by process via the default activity monitor application. Just double click on the relevant process on the list and select "Open Files and Ports" tab on the popup.
Tip: cmd+f shortcut on that pane allows for searching and highlighting on the content.
This works for some things:
sudo fs_usage | grep dev
for /dev/ files or similar.
The clean and simple approach to inspect the current process (i.e. the equivalent of /proc/self/fd on Linux) is to use ls /dev/fd/:
e.g.
$ touch "file"
$ exec 3<>file
$ ls /dev/fd/
0 1 2 3
List open files on /Volumes/VolumeName:
lsof | grep "/Volumes/VolumeName"
"You can get the list of open files by process via the default activity monitor application. Just double click on the relevant process on the list and select "Open Files and Ports" tab on the popup."
But "you had a hard time getting Activity Monitor to show open files for a process that was running as root (via sudo) or others user".
So just run Active Monitor by sudo, that`s it
sudo /Applications/Utilities/Activity\ Monitor.app/Contents/MacOS/Activity\ Monitor
I use the What's Open application that is very handfull (with filters, disk selection, ...).
You can find it there : http://whatsopen.en.softonic.com/mac.
Since you asked "Is there any other support [than lsof] available?", try this:
Create a command line tool using the "proc_pidinfo" C API referenced in the selected answer to this question: How can I programmatically get the list of open file descriptors for a given PID on OS X?
You can use proc_pidinfo with the PROC_PIDLISTFDS option to enumerate the files used by a given process. You can then use proc_pidfdinfo on each file in turn with the PROC_PIDFDVNODEPATHINFO option to get its path.
lsof -c /^74016$/ -d^txt -FcfadDtns0
The -F instructs lsof to produce output suitable for consumption by another process, such as Perl or awk. In man lsof search for OUTPUT FOR OTHER PROGRAMS for details. The characters that come after -F represent a field you want to select for output. The output then puts each of these characters in front of the respective field. Example output:
p212^#cloginwindow^#
fcwd^#a ^#tDIR^#D0x1000004^#s704^#n/^#
f0^#ar^#tCHR^#D0xf218cacb^#n/dev/null^#
f1^#au^#tCHR^#D0xf218cacb^#n/dev/null^#
f2^#au^#tCHR^#D0xf218cacb^#n/dev/null^#
f3^#ar^#tREG^#D0x1000004^#s216424^#n/Library/Application Support/CrashReporter/SubmitDiagInfo.domains^#
f4^#ar^#tREG^#D0x1000004^#s77^#n/private/etc/security/audit_user^#
f5^#ar^#tREG^#D0x1000004^#s652^#n/private/etc/security/audit_class^#
f6^#ar^#tREG^#D0x1000004^#s358^#n/private/etc/security/audit_control^#
f7^#ar^#tREG^#D0x1000004^#s111033^#n/System/Library/Frameworks/CoreImage.framework/Versions/A/Resources/ci_stdlib.metallib^#
f8^#au^#tIPv4^#d0xc401abd77f1dd1d9^#n*:*^#
f9^#ar^#tREG^#D0x1000004^#s308316^#n/System/Library/Frameworks/CoreImage.framework/Versions/A/Resources/ci_filters.metallib^#
f10^#au^#tREG^#D0x1000004^#s1536^#n/private/var/folders/4g/3lkhwv6n7_76_1s8snscvhxc0000gp/C/com.apple.loginwindow/com.apple.metal/3902/libraries.maps^#
f11^#au^#tREG^#D0x1000004^#s65536^#n/private/var/folders/4g/3lkhwv6n7_76_1s8snscvhxc0000gp/C/com.apple.loginwindow/com.apple.metal/3902/libraries.data^#
f12^#au^#tREG^#D0x1000004^#s1536^#n/private/var/folders/4g/3lkhwv6n7_76_1s8snscvhxc0000gp/C/com.apple.loginwindow/com.apple.metal/Intel(R) HD Graphics 630/functions.maps^#
f13^#au^#tREG^#D0x1000004^#s131072^#n/private/var/folders/4g/3lkhwv6n7_76_1s8snscvhxc0000gp/C/com.apple.loginwindow/com.apple.metal/Intel(R) HD Graphics 630/functions.data^#
p421^#ccoreauthd^#
fcwd^#a ^#tDIR^#D0x1000004^#s704^#n/^#
f0^#ar^#tCHR^#D0xf218cacb^#n/dev/null^#
f1^#au^#tCHR^#D0xf218cacb^#n/dev/null^#
f2^#au^#tCHR^#D0xf218cacb^#n/dev/null^#
p537^#cUserEventAgent^#
fcwd^#a ^#tDIR^#D0x1000004^#s704^#n/^#
f0^#ar^#tCHR^#D0xf218cacb^#n/dev/null^#
f1^#au^#tCHR^#D0xf218cacb^#n/dev/null^#
f2^#au^#tCHR^#D0xf218cacb^#n/dev/null^#
f3^#au^#tunix^#d0xc401abd77b9c8579^#n->0xc401abd77b9c8709^#
f4^#au^#tunix^#d0xc401abd77b9c7129^#n->0xc401abd77b9c8899^#

Pass multiple parameters with open command

I am looking for ways to open multiple documents in a single application instance. For example, open multiple documents in a single, new gVim instance.
I had found this code on here before, but it doesn't quite do what I want.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\Shell\Open with &Vim]
[HKEY_CLASSES_ROOT\*\Shell\Open with &Vim\command]
#="\"C:\\Users\\avt\\Programs\\PortableApps\\gVimPortable\\gVimPortable.exe\" -p --remote-tab-silent \"%1\" \"%*\""
The problem is that it is giving a similar effect, but not the one I want (it opens the selected documents in an existing gVim instance, not all of them in their OWN new gVim instance). What I want is like this:
Highlight 5 documents in Explorer
Open them
A single gVim instance opens with all 5 documents as tabs
I think this would work, if only I could pass multiple arguments!
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\Shell\Open with &Vim]
[HKEY_CLASSES_ROOT\*\Shell\Open with &Vim\command]
#="\"C:\\Users\\avt\\Programs\\PortableApps\\gVimPortable\\gVimPortable.exe\" -p \"%allselecteddocuments\""
Thanks!
EDIT: I just found out I can do this by adding a custom SendTo command (create a shortcut in your SendTo folder to gVim add -p to the Target. Is there any way to do this outside of the SendTo menu?
Create a shortcut in C:\Users\\\<user>\AppData\Roaming\Microsoft\Windows\SendTo folder with ONLY the exe name.
Now you should be able to select random multiple files and use context SendTo\<shortcut> to open them with your designated exe.

Accessing PowerShell history with up-arrow

I recently switched to powershell since my Cygwin bash started giving me senseless compilation errors when using maven. I've found how to save and restore my command history in (https://stackoverflow.com/questions/9259723/is-there-a-windows-shell-tool-can-keep-history), which seems to work (using "History" will show the recent commands after a clean start).
What I can't seem to do is access this history with the up arrow like you would if the command was used in the current session.
Any ideas?
I would suggest killing this old habit (I know, they die hard) and using PowerShell specific feature that is build for that. It's in fact pretty awesome. This is #*[tab], there are 2 options here (tab in brackets ([tab]) means that the tab button should be pressed):
#pattern_from_command[tab]
-> Powershell cycles through all commands in history that contain "pattern_from_command".
-> EG: In Powershell: type #echo, press tab -> Powershell cycles through all commands in history that contain "echo" (of course if any).
#<id>[tab]
-> Powershell completes command with id <id>.
-> EG: In Powershell: type #3, press tab -> Powershell writes the third (3) command in history to command line (though not executing it directly, just press enter to execute it).
I know it's not the same as you would do in bash, but I think it's worth trying and getting used to.
EDIT: It appears that recent versions of PSReadLine removed that functionality. You are better off with functionality in PSReadLine anyways, but if you want to give it a try in regular console, and it doesn't work - just
Remove-Module -Name PSReadLine
Functionality still works in any host that doesn't load PSReadLine by default (e.g. PowerShell ISE).
As of October 2013, this is now possible using the wonderful PSReadline module: http://github.com/lzybkr/PSReadLine
You'll still need to save your history when your powershell session exits and load it in your profile.ps1 prior to loading PSReadline (see http://technet.microsoft.com/en-us/library/ee156792.aspx). You can register a hook to save your history when PowerShell exists using a hook like this: Powershell profile "on exit" event?. Unlike vanilla PowerShell, PSReadLine allows the up/down keys to access this history buffer.
Like say #jhclark it is now possible
You have all the documentation for installation in the official GitHub : https://github.com/PowerShell/PSReadLine
You will have to follow the whole tutorial well and pay attention to:
remove -AllowPrerelease arg if you have error
add this line Import-Module 'PSReadLine' in your profile code $PROFILE for example to open your profile conf with vscode
Close all shell after you install PSReadLine if you want all work fine
Launch this two lines if you want the fleche to search in the history like on Linux because that is, I think, what most people are looking for:
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
by default are the key combinations F8 and SHIFT + F8 which are configured by default
You can see the conf with that :
Get-PSReadLineKeyHandler
You cannot. There is no API for accessing a console program's history.

Resources