I’ve been annoyed for awhile now that Safari was auto-opening text files that I was trying to download in rapid succession via option-click on a series of links. The text documents kept popping up in front of my browser window and getting in the way. Safari used to have preferences that you could set to tell it what to do with specific file types, but not anymore – at least not since Safari 10 on MacOS Sierra (10.12.x). The only options were to make Safari auto-open “safe” files or not auto-open any files at all. I was about to give up again. I’ve tried to figure this out on multiple other occasions, but I’d finally had enough and decided to roll my own using Automator and some clever scripting… Continue reading
We just moved, and in my last apartment, we lived on the second floor and I had my Foscam security camera [~$60] (which is controlled by the Basic version of Sighthound Video [$60]) trained on the only stairwell, which only captured people arriving or leaving. However in our new house, none of the doors are in locations where the camera only captures egress & ingress events. There’s a bathroom right next to one door and the other is between the living room and the stairs. Thus, anywhere I set up a security camera is bound to capture the regular activity inside the house. So I first experimented with setting the rules to make the cameras active during certain hours on the weekdays, which turned out pretty annoying, because my wife’s schedule is random. What I needed was a way to turn the camera rules off & on based on when we arrive & leave the house, the same way I use WeMo to control the window unit air conditioners and the air filter.
I discovered that Sighthound has an IFTTT channel and an iOS app, but their IFTTT channel only has triggers upon motion detection and no “actions” that could be run using Life360 (the app I use to control the AC & filter – e.g. turn on when the first person arrives and off when the last leaves or vice versa). So I emailed Sighthound to see if they had any tips for enabling and disabling camera rules. They pointed me to one of their forums called Hacker’s Corner, where I got pointed in the right direction.
Here’s how to enable your security camera (rule) when the last person in your family leaves the house and disable the camera when the first person in your family arrives.
Last winter, a house that I rent out sustained 11 thousand dollars worth of water damage because an ice jam formed above the gutters. I learned a lot about how this happens during the ordeal. Heat from the house melts the bottom layer of ice & snow on the roof. The water from the melting trickles down the roof, but once it gets to the eaves (away from the heat because the eaves are not enclosed and extend away from the house), it freezes and forms a dam. Since the water has nowhere to go, it backs up from the eaves between the roof and the ice above it and gets under the slates/shingles.
My tenants didn’t notice the water coming in in the dining room through the ceiling and walls until the damage had started showing on the first floor. Once I was alerted, I hired a company to come and remove the ice dam above the gutters.
The conditions needed for an ice dam/jam to form on the roof are 4 or 5 days where the temperature never gets above freezing and ice or snow has accumulated on the roof. Dealing with the ice jam was such an ordeal that this year, I wanted to figure out a way (or ways) to get an early warning that an ice jam could be forming.
I had an idea to use a moisture sensor in the windows that would sound an alarm if water made contact with the sensor. There was one window in particular where the water built up the most, so I bought this cheap moisture sensor (only $12) and installed it between the window and the storm window:
However, by the time it goes off, a good bit of damage will have occurred already. That makes it a good backup, but I needed something predictive. Long ago, I had tried looking into the possibility of getting weather alerts when the temperature stays below freezing for multiple days, however after installing tons of apps and even looking into IFTTT‘s weather channel, the best alerts I could find were when the temperature went below freezing on a single day. So today I finally sat down and rolled my own way to get an alert after 4 or more days of freezing temperatures in a row.
The basic idea was, I wanted to use IFTTT‘s weather channel to add tomorrow’s high temperature from the forecast to a google spreadsheet every day. I then would create a google script attached to the spreadsheet to email me when the last 4 entries in the spreadsheet all had values below 33 degrees (F). The script can be set to be triggered whenever a new row is added.
The first hurdle I faced was that IFTTT only lets you set 1 location for weather alerts and I already have my location set to where I live (not where the house I rent out is) and I already have weather recipes that rely on my location (e.g. when the pollen count gets high, turn on my air filter). If I was to change the location, all my recipes would use the new location, which made no sense. So I posted to the reddit IFTTT board and found out from the suggestions there that you can create multiple IFTTT accounts connected to the same gmail address by using gmail’s magical “+” feature. So if your gmail address is email@example.com, you can register an alternate IFTTT account using firstname.lastname@example.org. Note, after you create the account, you’ll need to go into your account settings and change your default username from “johndoe+ifttt1” to something like “johndoeifttt1” because IFTTT complains about the plus sign.
Next, you must create an IFTTT recipe (now called an “Applet”). The trigger will be the weather channel’s “tomorrow’s forecast” trigger and the action will be to add a row to a google drive spreadsheet. The settings when you’re done should look like this:
Note, you might need to add the Google Drive and WU Weather channels (now called “Services”) to your IFTTT account. Make sure to go into the weather channel’s settings to ensure it’s set to the correct location and that you’ve given IFTTT‘s google drive channel permission to access your google drive.
You then need to add a script to the spreadsheet. In the google docs tool bar, select “Tools->Script Editor…”. Replace the code there with the following code, but be sure to enter your email address you want to receive the ice jam warnings. Click the image to access copyable code on pastebin:
Save the script, click the “Select function” drop-down list, select the “createSpreadsheetChangeTrigger”, and click the play button.
You can now close the script editor window and test out your spreadsheet by entering temperatures in the first column. I entered “22”, 4 times to test it out. 2 things should happen upon entering the 4th value:
- You receive the email alert
- Column 3 gets the value “ICE JAM WARNING!”
Now, when IFTTT adds a row, if it’s the fourth or more day in a row of freezing temperatures, you’ll get an email warning that maybe you should check for an ice jam!
My wife just got a new job which has an irregular schedule and long hours. Unfortunately, I’d gotten accustomed to the fact that she always took care of feeding the cat and scooping her litter before I ever even thought about it. Now, a few weeks into this new job, I’m getting myself in trouble when I forget to feed the cat or scoop the litter. I imagine I’ll eventually get used to it, but until I do, I devised a clever way to get automatic reminders without me having to ask my wife her schedule every week and manually create the reminders, which means I’ll be less likely to forget. Hopefully, I’ll start to get used to the routine and I’ll be able to delete this reminder scheme, but until then, here’s how I managed to do it.
Internet accounts accessible via System Preferences are great. Everyone’s on board. E.g.:
You can create and maintain calendars in them and they all show up in your Calendar apps on your computer and on your mobile devices. In most cases, you create events and you create alerts for those events and you get your notifications the way you want them. Except Facebook. Sure, Facebook gives you your events and your notifications… and it even shows you events you’ve been invited to: great! What’s not so great? Your friends can create alerts on their events – events you have no intention of ever going to – events halfway across the world – and those alerts trigger on all your devices as if you created the event and set up the alert notification. Other internet accounts, like Google, draw the distinction between your events and events in others’ calendars you’re subscribed to, but did not create yourself. There are settings in your Calendar app that allow you to ignore alerts from these subscribed calendars. You can even choose to ignore alerts from subscribed calendars in your Facebook account’s calendar sync, but it doesn’t do anything because don’t forget, facebook adds your friends’ events to your calendar as if you created them. You’re ignoring nothing. You cannot stop the Facebook calendar notifications without turning off all notifications from every calendar in your Calendar app.
So you go about your day and your calendar alert goes off. You take a quick look and get confused about a meeting without a marked location. Then you start digging and find out it’s some event half way across the country about some distant acquaintance’s pub crawl that you got mass invited to. Then you start seeing these notifications all the time! Pretty soon, you stop looking at the alerts and you miss the reminder for your meeting that you scheduled! So annoying.
Being able to see what’s going on via Facebook events in your Calendar app is convenient when you’re looking for something to do in the context of your own schedule, so you hate to delete the Facebook calendar subscription. Luckily, I found a way to stop those pesky alerts, but still be able to see Facebook events in your Calendar app. Here’s how it works:
I’m one of those that does not normally restart my computer, however lately, the power in my office has been going out on a somewhat regular basis, which got me looking into finally automating the starting up of my iBeacon broadcasting. I had initially created a very quick automator app long ago by recording the 3 clicks it took to start the app, clcik the broadcast button, and then hide the window, but I found that, while it worked when I manually ran it, it always failed upon login (when set as a login item) with this error:
I was able to reproduce this error simply by messing around with (clicking) the mouse as the workflow ran, so I figured that had to have been the problem. Usually when I log in, I get asked for passwords and such and am rearranging windows on desktop spaces they’d been pulled from as a result of the logout. I sent a complaint via apple feedback regarding this issue:
Automator won’t run properly as a Login Item
I created an Automator “app” called “Toggle iBeacon Broadcasting”. I created it using the record feature. All it does is click on the BeaconOSX app in my dock, click the “startBroadcasting” Button, and finally, clicks the yellow hide button of the window. I put it as a Login Item so that my Mac would always be broadcasting an iBeacon signal. However, every time I log in, I get this uninformative error: [The action “Watch Me Do (Toggle iBeacon Broadcasting)” encountered an error. Check the actionʼs properties and try running the workflow again.] And every time I run it there-after, it runs fine. However, I was able to reproduce the error by clicking the mouse while it ran, so perhaps automator should detect stuff like that and pause with a dialog asking if it should proceed? Just a thought.
So since the recorded automator workflow had problems with mouse interference, I decided to try an applescript. The first problem I encountered was obtaining the app interface (and you’ll see this ends up being a recurring issue on multiple fronts). I have a handy applescript called getAppInterface that elucidates an app’s “accessibility” features, and the applescript language necessary to get to them, but I got an error from the system saying that Fastscripts (the menu-bar app I use to run scripts) didn’t have “assistive access” (despite it being in there already):
Error Number:System Events got an error: FastScripts is not allowed assistive access.
I’ve encountered this issue before. Apparently, if you edit a script or an app you’re developing, assistive access must be refreshed. So you have to remove and re-add it from the security preferences pane. More on enabling assistive access below, however something about Fastscripts must be changing, and I didn’t want to get into it. Running the script from applescript however worked and I was able to get the handles I needed to write the applescript that will start up the app, start broadcasting, and hide the window. It’s a pretty simple script:
tell application “BeaconOSX” to activate
tell application “System Events”
tell application process “BeaconOSX”
click button “Start Broadcasting iBeacon” of window “BeaconOSX”
click button “startAdvertising” of window “BeaconOSX”
click button 3 of window “BeaconOSX”
Note that the BeaconOSX app, as written, sometimes changes the button text of the start broadcasting button, so we try both if the first attempt does not work. If the button text is “Stop Advertising”, nothing will happen.
I added the applescript directly to my login items, but upon testing, I eventually concluded that the script was either not running or quietly failing. Regardless, I suspected that the accessibility security features could be again interfering with the functioning of the script and that perhaps Apple just had not built in a way to allow individual scripts assistive access. I didn’t want to deal directly with that, so I sent Apple another piece of feedback:
Too many hoops for login item scripts to get it to work
I had an automator-created recording that was not working (for unrelated reasons), so I wrote an applescript to start an app called BeaconOSX & click it’s broadcast button. The script runs fine manually, but adding it to my login items results in it quietly failing, after which the BeaconOSX window weirdly disappears. (Sometimes I can glimpse it in Mission Control by right-clicking the app in the dock & selecting show All Windows, but it promptly disappears for good once I select it.) Then I tried running it embedded in an automator app set as a login item. Finally I got asked to grant the app access in the security prefs upon login, after which, it worked, albeit very slowly (perhaps 20 seconds after login). The applescript should have worked without the automator wrapper.
Note, the feedback mentions another oddity: the disappearing of the iBeacon window. I do not believe this had anything to do with iBeacon itself, but rather the windowing system losing track of the window – perhaps because of the assistive access issue. Again, I didn’t want to deal with it – I just wanted something that would allow me to start up the broadcast reliably.
To get around this, as I alluded to in the feedback, I returned to Automator to embed the script in an app for which I could enable assistive access. Here’s how to do it:
Create a new automator application (not the default workflow) and drag the “Run Applescript” action from the main library to the pane on the right side and in between the “on run” / “end run” lines, replace whatever’s there with the above applescript. Save that as “StartiBeacon.app” and then add the app to your login items (System Preferences -> Users & Groups -> Current User (left pane) -> Login Items (tab)) by dragging it into the list of login items.
Then go to System Preferences -> Security & Privacy -> Privacy (tab) -> Accessibility (left pane)and add your app there as well. If you do not perform this step, the next time you log in, you will get the following error/notification combo:
Clicking the “Open System Preferences” button will bring you to this preference pane:
All you have to do is check the checkbox next to the StartiBeacon app listed there. Though you may need to unlock the preferences pane by clicking the lock icon in the lower lefthand corner. If you do that, you’ll be asked for your password:
After doing this, the next time you log in, your beacon should start broadcasting automatically, though I noted that it didn’t run for me until about 10-20 seconds after logging in.
This post is more of a description of what I went through to get this all to work. if there is a desire for a simple step-by-step how-to, please request it in the comments. I still have not managed to figure out how to tweak the iBeacon settings to get notifications at the expected distance, though I will say that one thing I’ve learned that is non-intuitive is that the higher you set the power, the better the accuracy of the distance measure. I believe, if I recall correctly, there’s a default distance that’s pretty short, though I’m still very vague on the details. That’ll be part 3 if I ever get it refined to go off just as I get into my office.
I keep a bunch of cheat-sheets & other various notes in Stickies.app, but I have less frequently needed notes in various other kinds of text files and it seemed that whenever I needed to find a certain command that I was sure I’d recorded somewhere, I could never find it. Well, I discovered the other day that Spotlight does not search the contents of Stickies notes. I read a lot about it in various blogs. I even tried to use a set of XCode 4.2 instructions in XCode 6 to create a Spotlight Importer for the Stickies database, but quickly discovered I was in over my head, so I set about constructing a hack to easily save all the stickies as backup text files that would be indexed and searchable by Spotlight.
The catch to this trick is the fact that I have various Sticky Notes bound to specific Mission Control desktops (some of which I hide under the dock with a huge font – to use as desktop labels) and the code for grabbing the stickies content required access to the visible window. I had first experimented with cycling through the desktops with key code trickery, but discovered a more efficient way – the Window menu item! Selecting a window in the window menu changes desktops implicitly, so I used the getAppInterface.scpt script (google shows that it’s not out there anymore, so if anyone requests it, I’ll post) to elucidate the menu interface and came up with this script.
set fileName to “”
set stickyNum to 0
set windowMenuListStart to 8
set destFldr to (choose folder with prompt “Choose a destination folder:”) as text
set mydestFldr to POSIX path of destFldr
tell application “Stickies” to activate
tell application “System Events”
tell process “Stickies”
set winMenuList to name of every menu item of menu 1 of menu bar item “Window” of menu bar 1
repeat with winMenuItemNum from windowMenuListStart to (count winMenuList)
click menu item winMenuItemNum of menu “Window” of menu bar item “Window” of menu bar 1 of application process “Stickies” of application “System Events”
set awindow to name of front window
set noteContent to value of text area 1 of scroll area 1 of window awindow
set stickyNum to stickyNum + 1
set fileName to “stickies” & “_” & stickyNum & “.txt” as string
set theFile to mydestFldr & fileName
do shell script “/bin/echo ” & quoted form of noteContent & ” > ” & quoted form of theFile
A few notes about the script… It needed a delay in order for mission control to be able to keep up with the script getting the front window. If you end up with duplicated and skipped notes, you might need to increase the number of seconds in the delay.
You can only run this script when the screensaver and screen lock is inactive, so putting it in a cron job is not a viable option. It will cause mission control to change desktops and you may not end up on the desktop you started on when it’s all done. I tried valiantly to find a way to determine the current desktop number but it looks like that is squirreled away in the code for the Dock and it very difficult to extract. What you might do to somewhat automate this so that you don’t have to periodically run it manually is use something like ScriptSaver to run the script just before the screen saver comes on. I have not tried this though and I don’t even know if ScriptSaver is still around.
One last note: if you try to debug an issue by adding dialog windows with messages, note that this will affect the “front window” function.
Once you’ve backed up your Stickies as text files and Spotlight has had time to index them, you will then see search results in the documents section with file names like “stickies_4.txt”. If you don’t want to wait for Spotlight to do the indexing on its own time, you can go to the Terminal and have it index your newly created stickies backup files with commands like this:
mdimport -d1 stickies_4.txt
The end result is that spotlight searches now show the contents of the stickies you’ve backed up. The caveat is that you have to occasionally run the script to keep them up to date. If anyone figures out a better way to do this, I’m all ears – so please comment below.