happyscripter
happyscripter
HappyScripter
2 posts
Don't wanna be here? Send us removal request.
happyscripter · 2 years ago
Text
Open the most recent file for a given folder
So at work we use this gem called letter_opener to handle emails in the local rails environment. When an email is sent in your rails environment, then letter opener stores it in tmp/letter_opener and automatically opens the email in your browser. It's very useful when resetting your password on local, or testing new mailers etc.
Brilliant, you say! Yes, it is. However, since we migrated to Docker in our local environment, the automagical opening in your browser feature no longer works. The email html still generates in the tmp/letter_opener folder but it's a pain in the neck to dig around in there every time you need to check an email. So I set about finding an alternative way to open the emails. I settled on a simple shell script that would find the most recent html file in the tmp/letter_opener folder and open it using the open command:
open $(find /path/to/search -type f -name "rich.html" -exec ls -lt -- {} + | head -n 1)
I have this assigned to a zsh alias called email. Every time I need to check an email I can trigger it and see the last email my rails app sent in my browser.
P.S. I've also been thinking about exploring using a mac folder action to achieve a similar feature to the original functionality. This would trigger whenever a new file appeared in the tmp/letter_opener directory and open it in the browser.
1 note · View note
happyscripter · 7 years ago
Text
Creating some useful keyboard shortcuts for Sierra’s picture-in-picture mode
I’m not sure about anyone else but I really like the native Mac OS picture-in-picture mode introduced in Sierra OS 10.12. But as seems to be the case for a lot of apple’s new features, there are no keyboard shortcuts and for me that simply won’t do!
So I’ve created three keyboard shortcuts that control the different aspects of the picture-in-picture mode:
One to play/pause videos
One to close the current video
And one to put the current video back
The hard work here is done with applescript and I make use of the System Events’ UI control library to simulate clicks on the buttons in the picture-in-picture window.
(You'll need a keyboard shortcut manager like BetterTouchTool or Alfred's PowerPack to assign the applescript to a shortcut. This tutorial will use BetterTouchTool)
So let’s run through how to make a keyboard shortcut. The shortcut we'll make will pause + unpause the video.
Setting up keyboard shortcuts
Launch BetterTouchTool, navigate to the Keyboard tab and create a new shortcut. Assign a shortcut by clicking the white field at the bottom left which reads "Click to record a shortcut" and pressing the desired shortcut. (I use alt-8 because that's just below the media play/pause key which makes it easy to remember.)
Under the "Trigger predefined action" field, select Controlling other applications > Run Applescript. Now, paste the code below into the text field and click Save:
tell application "System Events" click button 2 of window 1 of process "PIPAgent" end tell
Open a Youtube video in Safari, right click the video twice and select 'Enter Picture-in-Picture'.
Now test out the shortcut you made earlier and it should pause and unpause the video!
(N.B. Make sure to allow BetterTouchTool access privileges under 'Security & Privacy' in System Preferences.)
The rest of the code
For the other two shortcuts, follow the steps as above but use the following code instead.
Closes the current PiP window (I have this mapped to alt-X):
tell application "System Events" click button 1 of window 1 of process "PIPAgent" end tell
Puts the current PiP window back (I have this mapped to alt-M):
tell application "System Events" click button 3 of window 1 of process "PIPAgent" end tell
Wrapping up
I hope you enjoyed this post! Just a couple of notes - I really recommend getting Pipifier for Safari - it injects a little button into Youtube pages to make entering PiP much easier. (It works on hundreds of other video sites too!)
Also, I'll post up a little more info on how the applescript in these shortcuts works, and how you can use Accessibility Inspector to write similar shortcuts of your own. I also have some more complex Picture-in-Picture shortcuts that allow you to change which corner of the screen the window shows in, and to hide/unhide the PiP window, but I'll save those for another post.
That's all for now, thanks for reading! — happyscripter
1 note · View note