what do the parameter values in AppleSymbolicHotKeys plist dict represent? - macos

tl;dr
what does the first parameters value in com.apple.symbolichotkeys:AppleSymbolicHotKeys represent?
details...
the AppleSymbolicHotKeys structure
the OS X symbolic hotkeys plist file at
~/Library/Preferences/com.apple.symbolichotkeys.plist
stores hotkeys in a dict called as 'AppleSymbolicHotKeys' with entries that look like
<action:int> = Dict {
enabled = <enabled:bool>
value = Dict {
type = <type:string>
parameters = Array {
<param_1:int>
<param_2:int>
<param_3:int>
}
}
}
example:
10 = Dict {
enabled = true
value = Dict {
type = standard
parameters = Array {
56
28
1572864
}
}
}
pro tip: you can take a look with
/usr/libexec/PlistBuddy -c "Print :AppleSymbolicHotKeys" ~/Library/Preferences/com.apple.symbolichotkeys.plist
the values
action:int
this is the id of the action the hotkey will take. there are reasonably complete lists around the net, do some googling 'cause i don't have enough points to post links or whatever.
enabled:bool
whether the hotkey is enabled.
type:string
always seems to be 'standard'.
param_1:int
this is the one i can't get. it doesn't seem necessarily connected to params 2 and 3, though it often changes when the other params are changed. for instance...
i can click Restore Defaults in the System Preferences -> Keyboard -> Shortcuts -> Mission Control view, and it will set "Switch to Desktop 1" to "ctrl + 1". reading the value for that action (number 118), i see that param_1 is set to 65535. if i manually set the key combo to "ctrl + 1" in the UI, i get param_1 set to 49. the values of param_2 and param_3 stay the same throughout.
param_2:int
this seems to be key codes from
/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Headers/Events.h
for the non-modifier key to be pressed, except for the value 65535, which is very common in param_1, and shows up in param_2 on my local machine for actions 160, 163 and 175.
param_3:int
seems to indicate the modifier key to be depressed, as according to
MODS = {
0=>"No modifier",
131072=>"Shift",
262144=>"Control",
524288=>"Option",
1048576=>"Command",
393216=>"Shift + Control",
655360=>"Shift + Option",
1179648=>"Shift + Command",
786432=>"Control + Option",
1310720=>"Control + Command",
1572864=>"Option + Command",
917504=>"Shift + Control + Option",
1441792=>"Shift + Control + Command",
1703936=>"Shift + Option + Command",
1835008=>"Control + Option + Command",
1966080=>"Shift + Control + Option + Command",
}
where you will notice the numbers representing multiple modifiers are the sum of the modifiers they represent, e.g.
"Shift + Control" = 393216 = 131072 + 262144 = "Shift" + "Control"
so...
any insight would be greatly appreciated, and hope this can serve as a reference for the info i dug up to anyone else approaching the subject.

It is the ascii code of the letter on the key, or -1 (65535) if there is no ascii code. Note that letters are lowercase, so D is 100 (lowercase d).
Sometimes a key that would normally have an ascii code uses 65535 instead. This appears to happen when the control key modifier is used, for example with hot keys for specific spaces.
There is a nice list of keys and values from 2011 here, along with some other good details:
http://hintsforums.macworld.com/showthread.php?t=114785

The numerical values in nrser's answer make more sense when viewed in hexadecimal form:
0x000000 => "No modifier",
0x020000 => "Shift",
0x040000 => "Control",
0x080000 => "Option",
0x100000 => "Command",
The others are simply bit-wise-ORs of the above values, for example:
0x060000 => "Shift + Control",
0x180000 => "Command + Option",

In addition to what's already been said, I've compiled a JSON manifest of all 256 possible modifier bitwise-operated results — including the function keys:
https://gist.github.com/stephancasas/74c4621e2492fb875f0f42778d432973

Related

Ruby on Windows displaying wrong unicode character in cmd terminal

Title pretty much sums it up.
I'm trying to display the chess unicode characters in the win10 command prompt and it displays the replacement character (�) instead (copy pasting that gives me the correct character again)
Enforcing UTF-8 encoding.
Setting the CMD Charpage to UTF-8 encoding.
Using the unicode characters instead of codes in my strings.
$icons = {
"Pawn" => "\u2659", # ♙
"Rook" => "\u2656", # ♖
"Knight" => "\u2658", # ♘
"Bishop" => "\u2657", # ♗
"Queen" => "\u2655", # ♕
"King" => "\u2654", # ♔
"Black" => "\u25A0", # ■
"White" => " " #
}
class Graphics
def display_board(b);
system ("cls")
#system ("chcp 65001")
board = b.get_map();
board.each_with_index do |subarr,x|
str = "";
subarr.each_with_index do |value,y|
str += "[" + $icons[value] + "]";
end
puts(str);
end
end
end
Expected result is this :
[♖][♘][♗][♔][♕][♗][♘][♖]
[♙][♙][♙][♙][♙][♙][♙][♙]
[ ][■][ ][■][ ][■][ ][■]
[■][ ][■][ ][■][ ][■][ ]
[ ][■][ ][■][ ][■][ ][■]
[■][ ][■][ ][■][ ][■][ ]
[♙][♙][♙][♙][♙][♙][♙][♙]
[♖][♘][♗][♔][♕][♗][♘][♖]
Actual result :
� for every chess piece.
This doesn't appear to be a ruby problem but rather the default encoding setting for windows and which fonts are used by the command prompt cmd.exe.
Here's how you should be able to get this to work.
Download and install this free monospaced font.
right click windows start button and select Run then type regedit and enter
type in the following path HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont
Right click on the white area under the key entries and select new > string value
in the value data box type Droid Sans Mono
Click OK and then restart Windows.
Right click windows button > run > cmd
Right click the top of the window and select DejaVue Sans Mono font
Test it by typing this ruby -e 'puts "\u2658"'
You should see a font that outputs a knight ♘
For more help see https://www.thewindowsclub.com/add-custom-fonts-to-command-prompt
For other possible fonts which can be used see suggestions on this answer

In windows, how do I find out a folders sort by parameters

I am building an image viewing app in Node.js. I noticed that in Windows, the pictures in a folder can be sorted by name, size, status, type, date and tags etc, and grouped after sorting by the same list and more.
Is there a way of getting the sort parameters or maybe just retrieving the sorted list of files, matching the regular expression /\.(jpg|jpg_large|jpeg|jpe|jfif|jif|jfi|jpe|gif|png|ico|bmp|webp|svg)$/i, as an array (ex: ['c:\man.jpg', 'c:\woman.jpg'] using Powershell?
EDIT:
This article got me closer to a solution. https://cyberforensicator.com/2019/02/03/shellbags-forensics-directory-viewing-preferences/
Unfortunately it doesn't explain how to get the nodelist value for a given folder so I used an app called shellbagsview from nirsoft to get this value. In any case, if the value is found the rest is easy. I have included a sample python script which explains how this is done here.
from winreg import *
# Registry is of the form:
# HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags\1375\Shell\{5C4F28B5-F869-4E84-8E60-F11DB97C5CC7}
# where 1375 is a value called the NodeList, and {5C4F28B5-F869-4E84-8E60-F11DB97C5CC7} is a value under Shell chosen based on creation date. It is a good idea to look at the registry after getting the nodelist from shellbagsview
folder_reg_path = "Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\Shell\\Bags\\1375\\Shell\\{5C4F28B5-F869-4E84-8E60-F11DB97C5CC7}"
# the size of icons used by the folder
def get_folder_icon_size(reg_key):
with OpenKey(HKEY_CURRENT_USER, reg_key) as key:
value = QueryValueEx(key, 'IconSize')
return '%d pixels' % (value[0])
# the folder view. details, list, tiles e.t.c
def get_logical_view_mode(reg_key):
with OpenKey(HKEY_CURRENT_USER, reg_key) as key:
value = QueryValueEx(key, 'LogicalViewMode')
logical_view_mode_dict = {1 : "Details view", 2 : "Tiles view", 3 : "Icons view", 4 : "List view", 5 : "Content view"}
return logical_view_mode_dict[value[0]]
# folder view is based on view mode. so you can have a logical view mode of icons view with a view mode of large icons for instance
def get_folder_view_mode(reg_key):
with OpenKey(HKEY_CURRENT_USER, reg_key) as key:
value = QueryValueEx(key, 'Mode')
# view_mode 7 is only available on xp. A dead os
view_mode_dict = {1 : "Medium icons", 2 : "Small icons", 3 : "List", 4 : "Details", 5 : "Thumbnail icons", 6 : "Large icons", 8 : "Content"}
return view_mode_dict[value[0]]
# how is the folder being sorted
def get_folder_sort_by(reg_key):
with OpenKey(HKEY_CURRENT_USER, reg_key) as key:
value = QueryValueEx(key, 'Sort')
folder_sort_dict = {"0E000000" : "Date Modified", "10000000" : "Date Accessed", "0F000000" : "Date Created", "0B000000" : "Type", "0C000000" : "Size", "0A000000" : "Name", "02000000" : "Title", "05000000" : "Tags"}
# we get a byte value which we will hexify and get a rather long string
# similar to : 000000000000000000000000000000000100000030f125b7ef471a10a5f102608c9eebac0c000000ffffffff
reg_value = value[0].hex()
# now for this string, we need to get the last 16 strings. then we now get the first 8 out of it. so we will have
folder_sort_dict_key = (reg_value[-16:][:8]).upper()
return folder_sort_dict[folder_sort_dict_key]
# in what order is the folder being sorted. ascending or descending???
def get_folder_sort_by_order(reg_key):
with OpenKey(HKEY_CURRENT_USER, reg_key) as key:
value = QueryValueEx(key, 'Sort')
folder_sort_dict = {"01000000" : "Ascending", "FFFFFFFF" : "Descending"}
# we get a byte value which we will hexify and get a rather long string
# similar to : 000000000000000000000000000000000100000030f125b7ef471a10a5f102608c9eebac0c000000ffffffff
reg_value = value[0].hex()
# now for this string, we need to get the last 16 strings. then we now get the last 8 out of it. so we will have
folder_sort_dict_key = (reg_value[-16:][-8:]).upper()
return folder_sort_dict[folder_sort_dict_key]
icon_size = get_folder_icon_size(folder_reg_path)
logical_view_mode = get_logical_view_mode(folder_reg_path)
view_mode = get_folder_view_mode(folder_reg_path)
sorted_by = get_folder_sort_by(folder_reg_path)
sorted_by_order = get_folder_sort_by_order(folder_reg_path)
print ('The folder icon size is %s' % icon_size)
print('The folder logical view mode is %s' % logical_view_mode)
print('The folder view mode is %s' % view_mode)
print('The folder is sorted by %s in %s order' % (sorted_by, sorted_by_order))
The question itself and
the environment to run this in is unclear.
As you reference PowerShell and a RegEx to limit to specific extensions,
With this sample tree:
> tree /f a:\
A:\
└───Test
boy.bmp
child.ico
girl.gif
man.jpg
woman.jpg
this script:
Get-ChildItem -Path A:\Test -File |
Where-Object Extension -match '\.(jpg|jpg_large|jpeg|jpe|jfif|jif|jfi|jpe|gif|png|ico|bmp|webp|svg)$' |
Sort-Object Name |
Select-Object -ExpandProperty FullName |
ConvertTo-Json -Compress
yields:
["A:\\Test\\boy.bmp","A:\\Test\\child.ico","A:\\Test\\girl.gif","A:\\Test\\man.jpg","A:\\Test\\woman.jpg"]
The IShellView implementation (the file list part of Explorer) asks its IShellBrowser for a stream when it needs to load/save its state. My suggestion would be to host a IExplorerBrowser instance "browsed to the folder" and ask the view for its items. I don't know if you can ask it about which column it has sorted by but just getting the items in sorted order should be enough for your needs.
I don't know how to this in a scripting language but I assume PS supports enough COM for it to be possible.

How can I read the arrow keys in a Ruby curses application?

I have a Ruby curses application in which I'd like to trap for the arrow keys and function keys. The problem is that some keystrokes generate multiple values when using STDIN.getch. When I type a 'regular' key like a-z I get a single value back. When I type a [F]key or arrow key I get three values back.
Is there a gem designed for handling keyboard input or a better way to accomplish reading keystrokes?
#!/usr/bin/ruby
require 'curses'
require 'io/console'
Curses.noecho
Curses.init_screen
main_window = Curses::Window.new(24, 40, 1, 0)
num_keys = 0
loop do
ch = STDIN.getch
num_keys = num_keys + 1
main_window.addstr(' key:' + ch.inspect + ' count:' + num_keys.to_s)
main_window.refresh
break if ch == 'q'
end
Curses.close_screen
Trying enabling the keypad on the window right after you instantiate it.
main_window = Curses::Window.new(24, 40, 1, 0)
main_window.keypad = true
and then instead of using STDIN.getch there's a getch method on the window as well you can use, so try changing
ch = STDIN.getch
to
ch = main_window.getch
now when I run your program, I get
key: 259 count: 1
when I hit the up arrow instead of
key:"\e" count 1 key:"[" count:2 key:"A" count:3

How can I compress multiple lines of code into 1 line of code?

I have many similar block of code like this :
imgLoader({
img: $chImage,
btn: $btnAssignment,
imgPath: basePath + '04-Section Exercise/Assignment.png'
});
I want to compress them into 1 line.
imgLoader({ img: $chImage, btn: $btnAssignment, imgPath: basePath + '04-Section Exercise/Assignment.png' });
I did this one manually, and it takes me about 10 seconds.
Imagine doing 100 of these is clearly not fun.
I'm wondering if there is any Sublime Text 3 package/ plug-in that can help me do that.
It turn out that in Sublime Text, we can accomplish this such task, but just highlighting the texts, and press :
- Mac OS X : cmd + j
- Windows : ctr + j
Note: This will work only one way.
Sublime text has updated the shortcut, and it is now:
- Mac OS X : cmd + shift + j
Try using "find and replace" (ALT + CMD + F on Mac OSX)
Find: ,\\n and replace with: , then {\\n with { etc...
Also, a more complex Regex could do it in one go.

get random password with puppet function

I have a function that allow me to generate random password. My function is working well without a puppetmaster. When I tried with a master an error appear when I called the function :
Error 400 on SERVER: bad value for range
Here is my function:
module Puppet::Parser::Functions
newfunction(:get_random_password, :type => :rvalue, :doc => <<-EOS
Returns a random password.
EOS
) do |args|
raise(Puppet::ParseError, "get_random_password(): Wrong number of arguments " +
"given (#{args.size} for 1)") if args.size != 1
specials = ((33..33).to_a + (35..38).to_a + (40..47).to_a + (58..64).to_a + (91..93).to_a + (95..96).to_a + (123..125).to_a).pack('U*').chars.to_a
numbers = (0..9).to_a
alphal = ('a'..'z').to_a
alphau = ('A'..'Z').to_a
length = args[0]
CHARS = (alphal + specials + numbers + alphau)
pwd = CHARS.sort_by { rand }.join[0...length]
return pwd
end
end
The function is called in both case with $pwd = get_random_password(10).
When I specified the length directly in the function to 10 for example. The password is well generated in master mode.
Have you any idea why I can't specify the length value?
It's unclear why this works for puppet apply (if that's what you're insinuating), but the error is most likely a typing issue.
Try
length = args[0].to_i
To my Knowledge,For situations like this I use the puppet generate() function to create the random password and store it in a persistent data store on the master.
For instance,an SQLITE database or something. This way, the password is generated randomly if it does not exist and the same password is used if it does already exist.
It's important to have the resource always be managed, that way if the password is changed on the managed node Puppet will realize this, change it to the value you're managing, and report that it did so.

Resources