Category: Macro
Here are all posts from this category, beginning with the most recent.
A Script to Append Work Activity to a Log File
I used to have an AppleScript that would prompt me for some text and then append that to a file with a date and time stamp. The purpose of this script was to allow me to quickly log stuff that I was working on throughout the day. I launched the script with a keyboard mapping using FastScripts. I think I had it set to ⇧ + ⌘ + L.
At some point over the years and a couple of new computers later, I lost the script I found a copy of the script and recently became interested in adding this back into my workflow. Before I found it though, I used Kagi’s Quick Answer feature to cobble together a new version of the script.
set filePath to "Macintosh HD:Users:kevin:Documents:log.txt"
set isoDate to do shell script "date +'%Y-%m-%d %I:%M %p'"
try
-- Try to open the file for access
set fileRef to open for access file filePath with write permission
-- If successful, do something with the file
set userInput to ""
repeat until userInput is not ""
set userInput to text returned of (display dialog "What did you do?" buttons {"Cancel", "OK"} default button 2 default answer "")
end repeat
write return & return & "--- " & return & isoDate & return & return & (ASCII character 9) & userInput to fileRef starting at eof
on error errMsg number errNum
if errNum = -49 then
-- If the error is that the file is already open
close access file filePath -- Close the existing access
-- Now reopen the file
set fileRef to open for access file filePath with write permission
set userInput to ""
repeat until userInput is not ""
set userInput to text returned of (display dialog "What did you do?" buttons {"Cancel", "OK"} default button 2 default answer "")
write return & return & "--- " & return & isoDate & return & return & (ASCII character 9) & userInput to fileRef starting at eof
end repeat
else
-- Handle other errors
display dialog "An error occurred: " & errMsg
end if
end try
-- Close the file when done
close access fileRef
This is an improvement over my original script as it has better error handling and checks if the file is already open. I’m using Raycast as my launcher now and I’ve set it up to run this script by pressing the Hyper Key1 + L. I’m hoping to start using this regularly so I can have a good record of my work activites.
I still have the original log file that has entries going back 14 years, and it’s interesting to see what I was working on back then.
-
I mapped mine to the Caps Lock key. ↩︎
Disabling the Google Chat Service for Some Students
The administration of a high school wants to disable the Google Chat service for some students.
A simple way to accomplish this would be to create a group named “no-chat” and set the Google Chat service to OFF for that group. However, in Google Workspace, services can only be set to ON for a group. It would be ideal if OFF could also be set, but that’s not currently possible.
Another option would be to create a new Organizational Unit (OU), set the service to OFF for that OU, and move the necessary users to it. While this approach works, it complicates the OU structure, which could become increasingly complex when future changes are required.
So, what is the best solution?
Set the Google Chat service to OFF for the “/student/HS” OU. Then, create a group named “HS-google-chat,” add all active high school users as members, and set the Google Chat service to ON for that group. Finally, remove the students for whom Google Chat should be disabled from the group.
This solution seems promising, but what happens when new students enroll in the high school or former students re-enroll? How can the “HS-google-chat” group remain up-to-date with all the students who should have Google Chat enabled?
The answer is to use GAM!
What I came up with is a 3-step process. The first step exports all the active users from the high school OU. The second step creates a new .csv file that removes any students that are listed in a nochat.csv file. The final step synchronizes the HS-google-chat group from the revised .csv file.
All of these steps are added to a Bash script and run as a cron job. Here is an example of the Bash script:
#! /bin/bash
export PATH=$PATH:/home/user/bin/gam7
export GAMCFGDIR="/home/user/GAMConfig"
# This exports all active users from the HS OU to a csv named HS_users.csv
gam redirect csv /home/user/GAMWork/HS_Chat/HS_users.csv print users query "orgUnitPath='/student/HS' isSuspended=false"
# This creates a new csv file named HS_chat_users.csv that is all the HS_users
# except users who are in the nochat.csv file
awk 'FNR==NR {a[$0];next} !($0 in a)' /home/user/GAMWork/HS_Chat/nochat.csv /home/user/GAMWork/HS_Chat/HS_users.csv > /home/user/GAMWork/HS_Chat/HS_chat_users.csv
# This syncs the HS_google_chat group with the users in the HS_chat_users.csv
# file
gam update group HS-google-chat sync members csvfile /home/user/GAMWork/HS_Chat/HS_chat_users.csv:primaryEmail
Currently, changing the users who should have Google Chat disabled requires manually editing the nochat.csv file. What I’d like to have it do is pull the list of students from a Google Sheet that is edited by the high school administration. That would give them control over which students don’t get Google Chat.
EV Charging Noob
I made my first attempt to charge my EV at an Electrify America charging station. I tried to use the “second” plug on a unit, but another patron let me know that won’t work. Silly me, I thought two plugs on a unit meant two chargers. There’s two to accommodate either side of a car’s charging port location (the cords are short). There were no open chargers available and two other people waiting, so I left. I’m sure I provided a chuckle to everyone watching. Oh, well.
Adding Both Channels from a Dahua IPC Camera into VI MonitorPlus
In order to get both channels from a Dahua IPC-HDBW4231F-E2-M camera into VI MonitorPlus, select ONVIF as the manufacturer and ONVIF Profile S Compliant Camera as the model. Select the Shared IP Address checkbox and use Camera # 1 for channel 1 and Camera # 3 for channel 2 (camera numbers 2 and 4 are for the secondary streams). Each channel needs to be added as a seperate camera.
Style Guide
Here is a style guide for kevrodg.net. This is a regular paragraph. The Markdown syntax will make it easier to write blog posts.
Header 2
This is a paragraph below a level 2 header. Is there enough information here to make a qualitative judgement about this section? Here’s a little bit more text. I could type more here, but I think it’s enough.
Code Needed
I might write a post that has some code in it. That would look like this:
Typing ifconfig | grep netmask
in the CLI will show the IP addresses on a Mac.
Code blocks will look like this:
def reverse(text):
pos = -1
rev = ""
for i in text:
rev = rev + text[len(text) + pos]
pos = pos -1
print rev
reverse("Python!")
Blockquotes
Here is how blockquotes will look:
This is part of the blockquote. This is another part of the blockquote. How is Micro.blog handling all this?
This is a regular paragraph after a block quote. Nice, right?