Is there a way to use an Apple Script to control the brightness of the backlit keyboard on a Macbook?
The backlit keys are the F5 and F6.
Edit:
Based on the suggestion of #Clark I tried the follow, but it does not work.
NSAppleScript *run = [[NSAppleScript alloc] initWithSource:#"tell application \"System Events\" to key code 96"];
[run executeAndReturnError:nil];
Any suggestions?
Amit Singh has a chapter on how to do this from C.
https://web.archive.org/web/20200103164052/https://osxbook.com/book/bonus/chapter10/light/
It'd be easy to compile the sample code on that page and call it from Applescript.
To make Applescript type a function key you have to use the key code. The key codes fore the function keys are:
F1 = 122
F2 = 120
F3 = 99
F4 = 118
F5 = 96
F6 = 97
F7 = 8
F8 = 100
F9 = 101
F10 = 109
F11 = 103
To type one do something like this:
tell application "System Events" to key code 96
Related
I am working on an excel vba macro which opens some files but I ran into a problem, some files have a special character and I cannot copy it to be able to make a replacement, I even tried to find the ASCII code but it throws me the same code as the common space, I can only see it in MS Word.
The tiny circle is the special char:
You can recognize characters in Word:
Sub PrintASCII()
s = Selection.Text
For i = 1 To Len(s)
Debug.Print Asc(Mid(s, i, 1))
Next
End Sub
Usage: select the symbols and run this Sub. See output in VBE Immediate window
Output
95
95
95
95
160
95
95
95
95
95
13
I am trying to replace the tab with the expected output as "129hello3 78 0".Its showing same output after running the below mentioned lines of code.
I have given tab space between "129" and "3" and rest others are spaces
a="129 3 78 0"
b=a.replace('\t+','hello')
print(b)
There is no tab in a="129 3 78 0", but rather two spaces. For example, copy and paste tab from the text editor to ensure that the right character is in string a.
Here is the example:
a="129 3 78 0"
b=a.replace(' ','hello')
print(b)
a="129 3 78 0"
b=a.replace('\t','hello')
print(b)
The output is
129hello3 78 0
129hello3 78 0
In order to get this result, please open the editor of your choice (I am using Notepad here) paste the code there, and make sure that you have tab in required spaces (circled in red):
then copy the code from there and insert intoonline compiler of your choice ( I used https://www.programiz.com/python-programming/online-compiler/). Click Run
You are using replace instead of regex.
import re
a="129 3 78 0"
b=re.sub('[\t]+','hello', a)
print(b)
Or if you need replace:
a="129 3 78 0"
b=a.replace('\t','hello')
print(b)
I have a list of string like follow (each line is a string variable)
6.40 D5
8.45 F5
9.00 E5
10.30 D5
12.30 E5
13.00HUm5 <-- outlier, without space
13.15 F5
15.05 F5
15.45 Fm5
I simply want to split the time (the front one) from the attribute (the back one).
This can be simply achieved by str.split().
However, the problem is that there may be a case about an outlier string like 13.00HUm5, where there are no white space between time and attribute.
It will fail if I use the code above.
I want it to be ['13.00', 'HUm5']
How can I tell the code to split the string when an Alpha characters appears after a Digit characters ?
Is it possible to achieve something like that ?
Using Regex.
Ex:
import re
s = """6.40 D5
8.45 F5
9.00 E5
10.30 D5
12.30 E5
13.00HUm5
13.15 F5
15.05 F5
15.45 Fm5"""
for line in s.splitlines():
m = re.match(r"(\d+\.\d+)\s*(.*)$", line)
if m:
print([m.group(1), m.group(2)])
Output:
['6.40', 'D5']
['8.45', 'F5']
['9.00', 'E5']
['10.30', 'D5']
['12.30', 'E5']
['13.00', 'HUm5']
['13.15', 'F5']
['15.05', 'F5']
['15.45', 'Fm5']
I want to get the result from the cell in excel so that if F8 = .01 to .6 then it will show E8&A and if F8 = .7 to .125 then it will show E8&B. If not anything then it will show E8. I have wirtten that statement
(=IF(AND(F8>=0.01,F8<=0.06),E8&"A"),IF(AND(F8>=0.07,F8<=0.125),E8&"B",E8)
but it show #VALUE , what is the problem? Please help me
VALUE does not show after input the statement from your suggestion that
=IF(AND(F8>=0.01,F8<=0.06),E8&"A",IF(AND(F8>=0.07,F8<=0.125),E8&"B",E8))
but a problem newly create that
when I press .05 in F8 it shows E8&A but when I press .06 it shows only E8 and next when I press .07 it shows E8&B
my question is why it shows only E8 when I press .06 in F8
Thank you
It's because of the parentheses () used incorrectly.
=IF(AND(F8>=0.01, F8<=0.06),E8 & "A", IF(AND(F8>=0.07, F8<=0.125), E8 & "B", E8))
will work
Try:
=IF(AND(F8>=0.01,F8<=0.06),E8&"A",IF(AND(F8>=0.07,F8<=0.125),E8&"B",E8))
ie move the ) after "A" to the end.
Here you go. This implementation specifies something to do when values are outside of your ranges.
=IF(F8>=0.01,IF(F8>0.06,IF(F8>0.125,"Greater than 0.125",E8&"B"),E8&"A"),"less than 0.01")
You'll have to edit the formula based on what you want to happen to values between 0.06 and 0.07 (this is not specified in your question).
What does E8&"A" means? Try + instead of &...
=IF(AND(F8>=0.01,F8<=0.06),E8+"A"),IF(AND(F8>=0.07,F8<=0.125),E8+"B",E8)
I need to activate a popup when the user press a key board shortcut. Can you please tell me how this can be done?
Thanks!
This would be a javascript function. Take a look at onkeypress or onkeyup.
The best option is probably jQuery:
$(document).keyup(function(e) {
if (e.keyCode == x) {
//do something, i.e. alert('popup');
}
});
A few of the key codes:
Enter 13
Up arrow 38
Down arrow 40
Left arrow 37
Right arrow 39
Escape 27
Spacebar 32
Ctrl 17
Alt 18
Tab 9
Shift 16
Caps-lock 20
Windows key 91
Backspace 8
Home 36
End 35
Insert 45
Delete 46