Ultimaker 2+ Noise Dampening Foot

Noise dampening feet for Ultimaker2

Your Ultimaker is too noisy? Bring peace and harmony back in your living room with 3D printed noise dampening feet.

3D printers can be quite noisy. Besides a full encapsulation that might also proof valuable if printing ABS there are other ways to lower the volume. One is to reduce the vibration that is transferred from the moving parts of the printer to its case and from there to the table which resonates and, depending on size and material, is likely to subsequently work like a noise amplifier.

This effect can be reduced with noise dampening feet. There are a already lot of dampening feet designs available on Thingiverse or YouMagine so there is no need to design a new one. The Damping foot UM original by Kees de Ligt looks promising.

Dampening foot ok The first foot printed well with black REC filament using 0.15mm layer height, 0.8mm shell thickness, 35% infill, support, and with the square side facing the print bed. I use “hotter than normal” settings for the REC PLA: 215° noozle and 70° bed temperature. These temperatures provide nice prints and good platform adhesion with the REC filament. After that I got lightheaded and tried to print the remaining three feet all at the same time. While this is usually not a big deal, the REC PLA filament consistently turns out to be somewhat picky. Too much cooling time between the layers and the prints tend to fail.

This is how the three-at-the-same-time fail looks like.

Failed print Heavily warped edges on the bottom-most print. The first layers of the dampening foot in the middle look ok. But the top-most foot has been utterly destroyed. You’re on the lucky side if you notice such failures early enough to abort the print and, thus, avoid wasting material.

As I took a closer look at the dampening foot that was printed first, I realized that I would need two of the feet “as is” and another two feet mirrored at the y-axis. Only this way all four feet would face the same direction when attached to the printer. So, I should be thankful that the simultaneous print of three feet failed since that would have produced two unmirrored feet. You can easily mirror objects at all axes in Cura: Click the object then hit the mirror button on the bottom left and click on of the Mirror X/Y/Z buttons.

The remaining one foot as well as the y-mirrored two feet print like a charm. Attaching the feet is easy: Lift one corner of the printer and push the corresponding foot underneath this corner. Repeat with all other corners. Done.

All feet. All is good.

Rear foot compressed[Update] There is definitely a damping effect resulting in a less noisy soundscape. Good! But after a couple of prints the two rear feet have been tightly compressed so the curvatures of the snake-like construct touch each other. Hence, the damping characteristics of the rear feet are lost. Reason: The 35% infill and 0.8mm outer shell thickness are to weak to support the heavy rear part of the Ultimaker. Solution: Using 1.2mm outer shell thickness and 90% infill yields a new “as is” rear-left foot, and a new y-mirrored rear-right foot that are of heavy duty quality and now easily support the Ultimaker’s rear side.

How to easily use gmail for throwaway mail addresses

Fight spam and mail abuse! Use your existing gmail-address in a tricky way to generate an arbitrary number of throwaway mail addresses.

Spam, phishing, viruses, bots, ransomware… If you use e-mails as a communication method you are inevitably facing countless annoyances and threats. And the volume as well as quality of these threats is increasing. There is no way to use e-mail and completely and utterly avoid any contact with mail junk. Besides being heedful concerning sender, content, links, and, especially, attachments, there is one thing you can do that may help to decrease the amount of spam and other junk you receive via e-mail: Use throwaway e-mail addresses.

Throwaway e-mail addresses

A throwaway e-mail address is a mail address that is generated for a special purpose and discarded when it has done its duty. There are a couple of options to generate throwaway addresses:

  • If you are running your own server or hosting your own domain at an ISP create disposable e-mail addresses by using your mail servers catchall functionality.
  • Use an online service that is specialised on disposable mail addresses like throwawaymail.com, guerrillamail.com, or temp-mail.org.
  • Use gmail to generate throwaway addresses.

Let’s look at how to use gmail to generate disposable mail addresses.

Gmail: Generate arbitrary e-mail recipients with a “+”

A typical gmail address looks like this

abc@gmail.com

Now, to generate a new e-mail recipient you can add an arbitrary string of characters behind abc preceded by a plus “+” sign, e.g.,

abc+xyz@gmail.com

An e-mail sent to abc+xyz@gmail.com is just as well delivered to abc‘s inbox. And that is all there is to generate arbitrary e-mail recipients with gmail!

Fight e-mail abuse

How do you use a throwaway e-mail address to fight spam? If you register to an online store, say cheapcheapercheapest.com, you would no longer use your regular e-mail address abc@gmail.com but instead something like, e.g.,

abc+cheapcheapercheapest@gmail.com

Now, if cheapcheapercheapest.com got hacked or if they sold your e-mail address to spam-lists etc. potential mail abusers might get hold of this e-mail address which they will use to send their crap to. As soon as spam and other annoying stuff has been sent to abc+cheapcheapercheapest@gmail.com there is just one thing you have to do: Lock e-mails out that are sent to this address keeping your abc@gmail.com inbox clean. Let’s see how to do that with gmail.

Lock them out

Gmail is able to apply filter rules to incoming messages. These rules use one or more criteria like sender’s e-mail address, addressee, or specific words in the subject to identify an e-mail and apply one or more actions on it like marking as read, forwarding, moving to a folder, or deleting. Let’s define a deletion rule for an imaginary spam e-mail by the sender Spam-O-Mat that has been sent to foobar.io+antispam@gmail.com. This is the e-mail in foobar’s inbox.

zeropage-spam-1

This e-mail is, obviously, very suspicious. We want to see where it has been sent to, i.e., who the exact recipient is. Show the e-mails content by clicking on it. You would see something like this.

zeropage-spam-2

We do need the details so click the corresponding “show details”-button just below the sender’s name.

zeropage-spam-3

We get a popup window revealing more information about from, to, date, etc. The “to”-field shows who the exact recipient’s address. Here we see that this spam e-mail has been sent to foobar.io+antispam@gmail.com. Apparently, it was a good idea to use a throwaway e-mail address! We will define a filter rule to immediately delete all e-mails sent to foobar.io+antispam@gmail.com. Click the “more” button on the right-hand side of the e-mail header bar.

zeropage-spam-4

You will see a popup window with a couple of options. Choose “Filter messages like this”.

zeropage-spam-5

You will see another popup with the filter criteria. The To-field has already been filled with foobar.io+antispam@gmail.com. Nothing else to do here, just click on “Create filter with this search »”.

zeropage-spam-6

The final step where you choose what to do with the e-mail. Activate the option to “Delete it”. I suggest to activate “Also apply filter to 1 matching conversation” too so this new rule is also applied to the e-mail we started from as soon as the filter rule has been created.

zeropage-spam-7

Click “Create filter” when you are done. And you are done.

This looks and reads more complicated than it is. Once you know what to do it’s just a matter of seconds to have a filter rule in place. Keep your inbox clean!

RSS Feed Symbol

How to add images to your WordPress RSS Feed

Wordpress does not add images to your RSS feed. There are plugins to do the job but here is an alternative by adding some lines of code to functions.php.

I accidentically stumbled upon this unexpected WordPress behaviour. Looking for a solution I came across this post Beitragsbilder im WordPress RSS-Feed einbinden by Tobias Rieder. He explained how to add a few lines of code to the functions.php file to add a post’s featured image to the RSS feed.

Of course, you could install a plugin like “Featured Images in RSS w/ Size and Position” to have the same result. But that would be yet another plugin. And every plugin uses some processing time on your server. Moreover, tinkering the functions.php is how real men do stuff like that. 😉 Add the following lines to your theme’s functions.php. It is advised to use a child theme for modifications like this.

function post_thumbnail_in_rss( $content ) {
  global $post;
  if ( has_post_thumbnail( $post->ID ) )
    $content = get_the_post_thumbnail( $post->ID, 'medium', array( 'style' => '' ) ) . $content;
  return $content;
}
add_filter( 'the_excerpt_rss',  'post_thumbnail_in_rss', 1000, 1 );
add_filter( 'the_content_feed', 'post_thumbnail_in_rss', 1000, 1 );

You can choose the picture’s size to be either full, medium, or thumbnail. Using style in the array you can inject CSS styles, e.g. add a margin or a border to your picture.

Have at it!

RIBB@TACKING Bruce Lee – a C64 game tribute and homage

Bruce Lee homage and art project: A 3D rendered picture from the C64 Game "Bruce Lee" in an Ikea Ribba frame with Arduino magic for a cookoo's clock effect.

One day end of 2015 I stumbled upon some pretty kewl voxel art by Metin Sevin. Amongst many others like Mario Bros, Pacman, or Donkey Kong, I was immediately fascinated by the 3D rendered Bruce Lee Commodore 64 game tribute picture. I contacted Metin and asked him if his work is for sale and he kindly pointed me to society6 where a lot of his art is available in various formats. If you are interested in Metin and his work you can find out more in this interview at the end of this blog post. Due to some other planned projects based on Ikea Ribba frames I had one 23x23cm frame on stock so the 8″x8″ Bruce Lee art print would fit just fine. Shipment from Illinois/USA took about two weeks and I was ready to go for my art project!

tl;dr Watch the video to see what this project is about. Making of with gory details below video.

Project Description

Take the 8″x8″ Bruce Lee art print and put it in a 23x23cm Ikea Ribba frame. Use an Arduino to play the C64 Bruce Lee game title music at 12am and 7pm. Announce every hour starting with the first 3secs of Carl Douglas’ Kung Fu Fighting song and indicate the current hour by an according number of Yamo’s calls (the green Sumo in the game). Announce a quarter past, half past, and a quarter to with the Ninja’s stick strike sound ringing out once, twice, or thrice, respectively. Finally, add a capacative touch sensor to cycle through all Bruce Lee game sounds by touching one corner of the Ribba frame.

Payload

1 x 8″x8″ Bruce Lee art print from society6.
1 x RIBBA frame from Ikea seems no longer to be available. You could use a 25×25 cm Sannahed frame as a replacement.
1 x Visaton K28.40 8Ω, Price comparison idealo
1 x Arduino Nano e.g. from eBay
1 x LM386 Audio Amplifier Module e.g. from eBay
1 x DS3231 Real Time Clock (RTC) e.g. from eBay
1 x CR2032 battery for DS3231 RTC
1 x SD Card Module e.g. from eBay
1 x SD Card 1GB is sufficient
1 x 5V 1A power supply

Cables, solder and iron, hot-melt gun, screws, (cordless) screwdriver, drill, side cutter, etc.

A 1GB SD would have been sufficient since the WAVE files are very small. Unfortunately, I threw away old small capacity SD cards years ago “…when should I ever need a one or two GB SD card again?” Well, now I know the answer. Thus, I had to use an 8 GB SD card.

Audacity will be helpful to recode the Bruce Lee tunes to the required format.

Howto

Order the Bruce Lee voxel from society6. Wait approximately two weeks until it arrives; might heavily depend on where the item is shipped to. 😉 While waiting: a] Buy a 23x23cm RIBBA frame at your local Ikea. b] Prepare the necessary electronics and code to get the thing up and running.

Hardware

For the hardware part: Glue the required components, i.e. Arduino Nano, amplifier, SD card module, DS3231 RTC w/ CR2032 battery to the back of the RIBBA frame. It might look like this.

RIBBA frame with electronics

NB: This was my first shot with the loudspeaker directly glued to the backside as can be seen in the photo. My assumption that the – sort of abyssal – RIBBA frame will act as a good resonator
WAS WRONG. When I hung up the picture on the wall for the first time you could barely hear anything. The loudspeaker radiating directly to the wall was nearly completely muted since the sound waves cannot escape the frame.

Bruce Lee project Visaton SpeakeNew solution: Drill a plethora of holes into the bottom part of the frame and attach a (smaller) loudspeaker so that its sound waves can go through the holes. There are roughly 3 cm space between the backside (with the components) and the wall-facing side of the frame. Thus, I needed a speaker with a radius of max(3cm). I found an fairly good sounding 2,8x4cm rectangular-shaped speaker from Visaton that would fit snuggly into the available space (cf. picture).

Speaker drilling templateI created a drill template with the speaker’s exact dimensions by laying a piece of paper on top of it and tracing its contours with a pencil. Old school but works! After that I drew a mesh pattern with a lot of drill holes. That could have been the maiden trip for my drill press…but I went with the cordless screwdriver that did a nice job on drilling the 90+ holes. The template was fixed with sticky tape to the frame before drilling. I covered the whole template with tape to avoid frayed drill holes. This worked pretty good on the template Speaker drill holes burring done side but not on the inside of the frame. The RIBBA frame is made of chipboard so I lost quiet some material while drilling. You can see in the picture that the inside is not flat anymore but sort of curved due to the lost material. Next time I would apply sticky tape to the inside too.

After drillingThe holes needed some afterwork, i.e., burring and removing frayed pieces. The pictures do not show the final stage of afterwork so you will have to trust me that the result was ok. Especially, since the holes are on the bottom side that will, most likely, hardly been seen or looked at when the frame is hanging on the wall. I was happy with the result and moved on to screw the Visaton speaker into the frame with four black and tiny flat-head screws that were giving me a hard screwing time.

This is how the final setup looks like.

Visaton speaker attached

Note the blue cable going to the upper left corner?

This is the capacitive touch sensor wire. Capacitive touch sensor wire It is basically a piece of zinc coated copper wire bent to a 90° angle and sticked exactly to the corner of the frame using super glue. It was then painted black and soldered to the blue cable to have it connected to the Arduino. With this switch I would later be able to play all Bruce Lee game tunes one after another by repeatedly touching the bottom left corner of the frame. Actually, the ADCTouch-Library used is doing such a great job that the Arduino can react to a finger (or a hand, or some other body part) just coming near to the wire. You can measure changes in the wire’s capacity without even touching it. Awesome!

What’s missing? Yes, details on the wiring. The correct wiring might be hard to find out by just looking at the pictures, not least since my wire color scheme is a bit, eh, inconsistent. So here’s a Fritzing breadboard view of the wiring.

Bruce Lee RIBBA frame hanging on wall

That should cover the most important aspects of the hardware. But all this hardware is nothing without software. Let’s move into the matrix.

Software

Code is poetry

There are more lines of code in the Arduino sketch (GitHub) than needed to implement the behaviour as described in the Project Description. Nonetheless, some of the code is helpful for debugging purposes and some other for fiddling with the TMRpcm Library.

This library is used “for asynchronous playback of PCM/WAV files direct (sic!) from SD card”. The WAVE files must be in a specific format, i.e., 8-bit, 8-32khz Sample Rate, mono. Thus, do not expect Hifi quality! I wrote a separate article WAV-Dateien von SD-Karte mit Arduino abspiele where you will find the gory details about the required file format, how to convert, e.g., an mp3-file using Audacity into this specific WAV-format, how to format the SD card – if required, how the WAV-files have to be named on the SD card (8.3. SFN – short file name from the good ol’ MS-DOS times), and a short Arduino sketch to test the TMRpcm lib.

The ADCTouch library is required for utilizing capacitive touch sensors without any additional hardware.

Debugging with “Serial.print()” is not that funny so we’re using the Streaming library to provide a C++ like << operator that allows constructs like Serial << F( "Current volume is " ) << gVolume << "." << endl; which is very convenient. NB: With the macro F() you put strings in an Arduino's flash memory instead of the sparse static RAM (SRAM) leaving more space for variables and such. The ATmega328 chip found on the Uno has the following memory:

Flash  32k bytes (of which .5k is used for the bootloader)
SRAM   2k bytes
EEPROM 1k byte

Flash is plenty but SRAM isn't - so there is reason to always save SRAM!

Finally, we need the DS3232RTC and Time library to handle the real time clock. Europe will not let go of the daylight saving time (DST) idiocy. Summer time is switched on at the last Sunday in March where 2 o'clock becomes 3 o'clock. Vice versae at the last Sunday in October where 3 o'clock becomes 2 o'clock. We have to recognize the DST so the Bruce Lee cookoo works both in summer and winter. 😉 Thanks to user "jurs" from the German Arduino Forum we have a great European daylight savings time calculation function fIsSummertime() that returns "true" when we're in summer time and false if not.

The Arduino sketch

Sketch also available on GitHub in the RIBBAttacking-Bruce-Lee repository.


Interview with the artist

Metin and I had a nice e-mail-chat while the project was ongoing. There are quiet some analogies in our CVs like being born in the 1970s, growing up with 8-bit computers, adjusting the datassette's azimuth with a screwdriver, hanging out at arcade halls, and - of course - liking minimalistic pixel graphics. Here is short interview with Metin to get you in touch with him as a digital artist and his voxel creations.

Metin, who are you?
My name is Metin Seven, I was born in the 1970s, and grew up in the 1980s with the first 8-bit and 16-bit generations of game consoles and 'home computers', particularly the Atari 2600, CBS ColecoVision, Commodore 64 and Commodore Amiga.

What is your artistic spectrum, i.e., what kind of art do you make/prefer?
I'm a die-hard digital artist. I used to draw on paper as well, but I prefer the flexibility of the digital screen. I started creating pixel art for Amiga demos in the late 1980s. That soon evolved into creating pixel graphics for commercial games, television commercials and children's animation series in the 1990s, all done using software like Deluxe Paint and Personal Paint on an Amiga. Since the late 1990s I've shifted towards 3D graphics creation, but pixel art will always keep a special place in my heart.

Why retro games and what is your reference to this genre?
Ever since I was a little kid I was enchanted by the magic glow of the digital screen. I used to hang out at arcade halls, playing the first 8-bit games, such as Donkey Kong, Lady Bug, Pac-Man and Pengo. When I was not playing them myself, I could stare at people playing the games for hours. The first pixel graphics had this pure, iconic quality because of the low resolution restrictions for sprites and such. It's great to see that atmosphere return in the current wave of minimalistic pixel art games for mobile devices.

Did you have decent experiences with the C64?
Definitely. During my school days I spent just about every afternoon and evening playing Commodore 64 games, first loading them using the Datassette tape recorder, adjusting the azimuth when necessary. After a while I bought a floppy disk drive. LOAD "*",8,1 😀

How did you come to create voxel pictures? Where does the idea come from?
During the 2000s I created a lot of stylized 3D illustrations for printed magazines and newspapers. My use of shapes and colors reflected my game pixel art background, and gradually my illustration style became more elementary, until I arrived at a point that fully made sense — a blend between pixel art and 3D artwork: voxels. It was then that I decided to start paying tributes to my childhood love: 8-bit and 16-bit games.

Can you tell us something about the voxel creation process?
My first voxel images were created in 3ds Max in the mid-2000s, extruding blocks of quadrangular polygons. That was quite a hassle, and I was eager to find a dedicated voxel editor. I found that in the shape of Paint3D for Windows. I got in touch with the coder and suggested a number of features, which he kindly implemented.

When I switched to Mac OS X in 2014, I started using Qubicle, also a versatile voxel editor. I guess MagicaVoxel would be the tool of my choice today, but to be honest I've become a bit saturated when it comes to voxel creation, although there’s a good chance I'll return to it some day.

Where should we go if we'd be interested in more from you?
The best starting place is my portfolio site metinseven.com, there you will find links to my online shops, offering 3D prints, 2D art prints, stock 3D models and stock illustrations.

Many thanks for this interview, and my sincere compliments to you regarding your clock creation based on my voxel tribute to the classic 8-bit Bruce Lee game.

The pleasure was all mine! Keep on the good work!

Bruce Lee RIBBA frame hanging on wall

i.f.

Lautsprecher

WAV-Dateien von SD-Karte mit Arduino abspielen

Musik und Geräusche mit einem Arduino abspielen? Kein Problem mit dem guten alten WAVE-Format, einem SD-Kartenleser und der TMRpcm Library.

Arduino WAV Musik SD-Karte Eins gleich vorweg: Hifi-Qualität darf man von der hier beschriebenen Lösung nicht erwarten. Aber als Low-Budget-Player für einfache Zwecke reicht es auf jeden Fall. Habe ich beispielsweise hier im Kunstprojekt RIBB@TACKING Bruce Lee – a C64 game tribute and homage verwendet.

Was man braucht

Natürlich einen Arduino; der hier beschriebene Aufbau wurde mit einem Uno getestet. Alle 328er basierten, also auch Nano, LilyPad, Pro etc. sollten gleichermaßen funktionieren.

Da die WAVE-Dateien irgendwo abgespeichert sein müssen, bietet sich ein SD Kartenleser an. Es gibt Breakout Boards mit Micro-SD-Karten Slot oder andere Shields, auf denen solch ein Slot bereits integriert ist, bspw. das Ethernet-Shield. Hier kommt ein sehr einfacher 1 EUR SD-Kartenleser von eBay zum Einsatz. Dazu eine (alte) SD Karte.

Damit man etwas hört, braucht es einen Verstärker. Bryan beschreibt in diesem Blog-Artikel, wie man mit einem einzigen Transistor nebst Widerstand (4,7 kOhm) einen simplen Verstärker zusammenschustert. Der BC548B hat nicht ausreichend verstärkt. Mit dem 2N3904 (eBay) macht es mehr Spaß.

Dazu natürlich ein Lautsprecher, da hatte ich noch einen mit 0,25 Watt 4 Ohm auf Halde liegen.

Verkabelung / Aufbau

Die Anbindung des SD-Kartenlesers erfolgt über die Hardware SPI Pins des Arduino. Welche Pins das genau sind, hängt vom Arduino-Typ ab. Die hier gezeigte Verkabelung sollte für alle 328er Typen (Nano, Uno, etc.) funktionieren. Chip Select ist frei wählbar; vgl. auch der weiter unten stehende Arduino Sketch. Die Schaltung auf dem Breadboard ist der erwähnte Ein-Transistor-Verstärker. Wenn man hier den Widerstand zwischen Arduino-Ausgang (Pin 9) und der Transistorbasis zu klein wählt, kann man nach kurzer Zeit auf dem Transistor Eier braten, da zu viel Strom durch die Collector-Emitter-Strecke fliesst.

Arduino-WAVE-Player-Steckplatine-Breadboard-450x345

Wagemutige können den Widerstand einfach mal ganz weglassen und sich an einer, dann, recht ordentlichen Beschallung nebst Transistorheizung erfreuen. Das sei hiermit also ausdrücklich nicht empfohlen.

Kartenleser PIN Arduino PIN Was ist das?
GND GND Ground
+5V 5V Volle Power! 🙂
MOSI 11 DATA, MOSI DATA, SDA, Hardware MOSI
MISO 12 MISO, Hardware MISO
CLK 13 CLK, SCL, Hardware SCK
CS 4 CS, Chip Select
GND GND Ground

In der Tabelle ist die PIN-Verkabelung noch einmal aufgeführt. Der verwendete SD-Kartenleser hat zwei GND-Anschlüsse und funktioniert auch nur zuverlässig, wenn tatsächlich beide mit Masse verbunden werden. Der Lautsprecherausgang ist, ebenso wie Chip Select, über den Arduino Sketch frei wählbar (hier PIN 9).

Zwei Blog Posts haben bei Verkabelung und Inbetriebnahme gut geholfen. Zum einen dieser Beitrag bei maxoffsky.com sowie insbesondere diese Anleitung auf instructables.com.

Format der SD Karte

Die verwendete SD-Library unterstützt prinzipiell die Dateisysteme FAT16 und FAT32. Es wird jedoch empfohlen, wenn möglich, FAT16 einzusetzen. Bei mir hat’s mit einer FAT32-formatierten SD-Karte nicht funktioniert, daher wollte ich sie “mal eben” auf FAT16 formatieren. Das geht auch mit MacOS Bordmitteln, ist aber etwas komplizierter, als erwartet. Dieser Post im Adafruit-Forum beschreibt den Weg in Englisch; hier in knappem Deutsch:

  1. SD-Karte in den Mac stecken.
  2. Terminal-Fenster öffnen. Bspw. mit CMD+Space, dort “terminal” tippen und Return.
  3. Geräte-ID finden. Dazu im Terminal df gefolgt von Return eingeben. Es erscheint eine Filesystem-Übersicht, die unter anderem die folgenden Informationen enthält. Ganz unten ist die SD-Karte “NO NAME” zu sehen. Wer auf Nummer sicher gehen will, gibt seiner Karte einen eindeutigen Namen. Dann kann man sie in dieser Übersicht schneller finden. Die in den folgenden Schritten benötigte Geräte-ID lautet /dev/disk3s1.
    Filesystem        Used Available Capacity   iused   ifree %iused  Mounted on
    /dev/disk1   909007896  65197032    94% 113689985 8149629   93%   /
    devfs              371         0   100%       642       0  100%   /dev
    map -hosts           0         0   100%         0       0  100%   /net
    map auto_home        0         0   100%         0       0  100%   /home
    /dev/disk3s1     20928   4172608     1%       512       0  100%   /Volumes/NO NAME
    
  4. SD-Karte unmounten (nicht auswerfen!). Im Terminal diskutil unmount /dev/disk3s1 gefolgt von Return eingeben. Dabei disk3s1 natürlich durch die eigene Geräte-ID ersetzen. Erfolgreiches unmounten wird bspw. mit Volume NO NAME on disk3s1 unmounted quittiert.
  5. FAT16 Filesystem auf SD-Karte schreiben. ACHTUNG! Der folgende Befehl löscht alle Daten auf dem Gerät. Wenn die Geräte-ID nicht die von der eingesteckten SD-Karte ist, sondern bspw. aus Versehen die der eingebauten Festplatte, dann wird diese gelöscht. U have been warned.
    Folgendes Kommando im Terminal eingeben und nicht vergessen die Geräte-ID anzupassen. newfs_msdos -F 16 /dev/disk3s1
    Ich habe alle Warnmeldungen, die der Befehl produziert hat, konsequent ignoriert und als Lohn der Mühe im Anschluß eine lauffähige FAT16-formatierte SD-Karte gehabt.

Format der WAVE Dateien

Die Library TMRpcm benötigt zum Abspielen die WAVE-Dateien im Format acht Bit, acht bis 32 kHz Sample Rate, mono. Im WIKI zur Library werden zwei Wege beschrieben, wie man iTunes oder Audacity verwenden kann, um aus dem musikalischen Quellmaterial das Zielformat zu generieren. Audacity ist prima, und so geht’s damit:

  1. Hauptmenü “Tracks”, dort “Stereo Track to Mono” wählen.
  2. Unten links die “Project Rate (Hz)” mit dem Popup auf 8000, 11025, 16000, 22050 oder 32000 setzen. Je niedriger die Sampling Rate, desto schlechter die Qualität.
  3. Hauptmenü “File”, dort “Export Audio…” und im File Selection Dialog unten als Format “Other uncompressed files” wählen. Dann “Options…” klicken und als Header “WAV (Microsoft)” sowie bei Encoding “Unsigned 8-bit PCM” wählen. OK.
  4. Datei mit “Save” speichern.

Dateinamen

Dateinamen müssen zwingend dem – aus alten MS-DOS Zeiten bekannten – 8.3-Format folgen, also maximal acht Zeichen für den Dateinamen gefolgt von Punkt und einer Endung mit drei Zeichen beispielsweise “NAME0001.EXT”. Der Dateiname kann kürzer als acht Zeichen sein, in keinem Fall aber länger. Die Wikipedia widmet dem 8.3 short filename (SFN) tatsächlich einen eigenen Artikel.

Arduino Sketch

Der folgende Sketch bindet zunächst die benötigten Libraries ein, definiert Chip Select- und Lautsprecherausgangs-PIN, initialisiert die SD-Karte mit SD.begin() und spielt im Erfolgsfall die Wave-Datei snakec16.wav direkt von der SD-Karte ab. Im Fehlerfall wird eine kurze Meldung über den seriellen Monitor ausgegeben.

#include 
#include 
#include 
#define CHIP_SELECT_PIN  4
#define SPEAKER_PIN      9
TMRpcm tmrpcm;

void setup( ) {
  tmrpcm.speakerPin = SPEAKER_PIN;
  Serial.begin( 9600 );
  while ( !Serial ) /*mt*/ ;
  if ( !SD.begin( CHIP_SELECT_PIN ) )
    Serial.println( "SD fail" );
  else {
    tmrpcm.play( "snakec16.wav" );
    delay( 5 );
  }
}

void loop( ) {
}

Wenn alles läuft…

…dann sollte das in etwa so aussehen, wie in dem Video.

Musik © Snake Charmer (Synapsis) / CC BY-ND 4.0

OLED 0,96″ Zoll Display an den Arduino anschließen

OLED Displays für den Arduino sind beliebt. Ein kurzer Wegweiser durch Anschluß-Pins, Protokolle und Libraries, damit das Mini-Display auch etwas anzeigt.

Bei eBay, Aliexpress & Co. gibt es zahnlose Mini-OLED-Displays, beispielsweise für den Betrieb an einem Arduino. Dabei sind die gängigen Größen 0,96 Zoll und 1,3 Zoll mit Auflösungen von 128 x 64 oder 128 x 32 Pixeln. Die Displays sind selbstleuchtend und werden in weiß, blau, gelb, Kombinationen davon oder auch “full color” angeboten. Die Full Color Displays stellen dann üblicherweise 65K Farben dar.

Es werden unterschiedliche Kommunikationsprotokolle unterstützt, in der Regel entweder I2C oder SPI oder beides. Dazu kommen unterschiedliche Driver Chips, für die die richtige Library benötigt wird, um das OLED ansteuern zu können. Gängig und gut unterstützt ist der Driver Chip SSD1306, der u.a. mit den folgenden beiden Libraries angesteuert werden kann: Adafruit_SSD1306 (github) oder U8glib (github). Wer ein OLED mit SS1106 Driver Chip erwischt hat, kann es mit der SH1106_SPI Library (github) versuchen.

Dieser Post zeigt den Anschluß und Betrieb eines einfachen, weißen 0,96″ Zoll OLED Displays (eBay) mit SSD1306 Driver Chip und sieben Anschluss-Pins an einen Arduino Uno. Nano, und alle weiteren Modelle mit ATmega328 Pinout, dürften auf dieselbe Weise angesteuert werden können. Im Zweifel das Datenblatt des Arduinos zu Rate ziehen.

Im folgenden Video ist das OLED im Einsatz zu sehen. Die Chord-Animation ist von Hari Wiguna, sein Kode steht auf GitHub bereit.

Um ein OLED erfolgreich ansteuern zu können, ist die richtige Verdrahtung zwischen Arduino und Display wichtig. Dabei wird es durch die Tatsache, dass die Displays mit unterschiedlicher Anzahl und Beschriftung der Pins geliefert werden nicht einfacher. Die Libraries erlauben üblicherweise die Verwendung von Software oder Hardware SPI, wobei letztere Variante deutlich schneller ist. Hardware SPI erfordert mehr Anschluss-Pins als Software SPI.

OLED Anschluss Arduino PIN Was ist das?
GND GND Ground
VCC 5V Volle Power! 🙂
D0 13 CLK, SCL, Hardware SCK
D1 11 DATA, MOSI DATA, SDA, Hardware MOSI
DC 6 Data/Command
DS 7 CS, Chip Select
RES 8 Reset

Das im Video gezeigte 0,96″ Display ist zur Ansteuerung durch Hardware SPI entsprechend der Tabelle mit dem Arduino zu verbinden. Bitte unbedingt prüfen, ob das eigene Display für 5V ausgelegt ist! Im Zweifel am 3,3V Pin anschließen und erst einmal damit versuchen. Die “Was ist das?”-Spalte in der Tabelle zeigt die ausgeschriebenen, gängigen oder alternativen Bezeichnungen der Anschlüsse; vielleicht hilft es dem einen oder anderen bei der Verkabelung. Ich fand diesen Beitrag von paulwb im Adafruit-Forum sehr hilfreich, um das Display nach einigen erfolglosen Versuchen endlich zum Laufen zu bringen.

Hier noch der Arduino-Sketch zur Darstellung der Animation wie im Video.

#include 
#include 
#include 
#include 

/* Wiring for Hardware SPI
    GND ------- ground
    VCC ------- 5V
    D0 -------- 13 hardware SCK
    D1 -------- 11 to hardware MOSI
    DC -------- 6 (user choice, defined below)
    DS -------- 7 (user choice, defined below)
    RST ------- 8 (user choice, defined below)
  Hardware MISO (12) unused */

#define OLED_DC     6
#define OLED_CS     7
#define OLED_RESET  8
Adafruit_SSD1306 display( OLED_DC, OLED_RESET, OLED_CS );

void setup( ) {
  display.begin( );
  display.clearDisplay( );
  display.display( );
}

int nFrames = 36;
void loop() {
  for ( int frame = 0; frame < nFrames; frame++ )
    HariChord( frame );
  for ( int frame = ( nFrames - 1 ); frame >= 0; frame-- )
    HariChord( frame );
}

void HariChord( int frame ) {
  display.clearDisplay( );
  int   n   = 7;
  int   r   = frame * 64 / nFrames;
  float rot = frame * 2 * PI / nFrames;
  for ( int i = 0; i < ( n - 1 ); i++ ) {
    float a  = rot + i * 2 * PI / n;
    int   x1 = 64 + cos( a ) * r;
    int   y1 = 32 + sin( a ) * r;
    for ( int j = i + 1; j < n; j++ ) {
      a  = rot + j * 2 * PI / n;
      int x2 = 64 + cos( a ) * r;
      int y2 = 32 + sin( a ) * r;
      display.drawLine( x1, y1, x2, y2, WHITE );
    }
  }
  display.display( );
}

Zugriff auf Photo Stream Bilder auf dem Mac ohne Photos App

Man kann auf dem Mac auf die Bilder des Photo Streams auch OHNE Photos App zugreifen. Hier wird der zugehörige Lösungsweg beschrieben.

Der Use Case: Mit dem iPhone, iPad oder iPod geknipste Bilder können über die sog. “My Photo Stream”-Funktionalität automatisch auf die jeweils anderen, verbundenen Geräte übertragen werden. Das ist praktisch. Es wäre aber noch praktischer, wenn diese Bilder ebenso automatisch auf den Mac synchronisiert würden. Das ist möglich, erfordert aber ein paar Handgriffe. Insbesondere, wenn man eine Lösung sucht, bei der man nicht die Photos App verwenden möchte und die Bilder in einem beliebigen Zielordner landen sollen. Hier das Vorgehen, inspiriert durch einen Artikel auf bockenhauer.com, den es dort allerdings nicht mehr gibt.

Wie funktioniert’s?

Wir schalten sowohl auf dem gewünschten mobilen Gerät, also iPhone, iPad oder iPod, als auch auf dem Mac die “My Photo Stream”-Funktion ein. Danach landen alle mit dem mobilen Gerät aufgenommenen Bilder sowohl (und wie bisher) im “Camera Roll”-Ordner und (neu) zusätzlich in einem Ordner mit dem Namen “My Photo Stream”. Zeitgleich werden die Bilder auf alle verbundenen Geräte in deren “My Photo Stream” Ordner gespiegelt. Beim Mac gibt es aber einen solchen Ordner nicht. Stattdessen werden die Photo Stream Bilder in einen Unterordner des Photos App Packages gelegt. Die hier beschriebene Lösung greift auf diesen Ordner zu und verschiebt die Bilder in einen Wunsch-Zielordner.

My Photo Stream auf dem Mac

Eine kurze Schritt-für-Schritt-Anleitung, um einen “My Photo Stream”-Ordner auf dem Mac zu emulieren.

  1. Photo Stream einschalten. Das ist an vielen anderen Stellen im Netz schon detailliert beschrieben, bspw. hier. Die Kurzversion für’s iPhone: Settings → iCloud → Photos → “My Photo Stream” einschalten. Und für den Mac: System Preferences → iCloud → dort rechts bei Photos den Options-Button klick → “My Photo Stream” einschalten. Kann man alternativ auch über die Settings der Photos App einschalten, aber viele Weg, Rom, etc. pp. NB: Weder “iCloud Photo Library” noch “iCloud Photo Sharing” müssen eingeschaltet sein, damitdie hier beschriebene Lösung funktioniert.
  2. exiv2 installieren, falls noch nicht vorhanden. Die Lösung setzt zum Umbenennen der jpeg-Dateien auf Basis der im jpeg-Header (hoffentlich) vorhandenen EXIF-Informationen auf exiv2. Das Tool lässt sich einfach via (home)homebrew installieren, und zwar so:
    $ brew install exiv2
    Wenn der Packet-Manager brew noch nicht vorhanden ist, dann natürlich erst einmal homebrew installieren…
  3. Shell Datei anlegen. Das folgende Shell-Skript den eigenen Bedürfnissen anpassen und dann in einem Verzeichnis bspw. als photostream.sh speichern.
    #!/bin/bash
    
    # Alle Photo Stream Bilder in den Ordner ~/Downloads/MyPhotoStream/_tmp kopieren
    find ~/Pictures/Photos\ Library.photoslibrary/Masters/ -type f -exec cp "{}" ~/Downloads/MyPhotoStream/_tmp/ \;
    
    # in das _tmp Verzeichnis wechseln
    cd ~/Downloads/MyPhotoStream/_tmp
    
    # Mit dem Programm exiv2 das Aufnahmedatum aus den EXIF-Daten jeder jpg-Datei auslesen.
    # Der Parameter -t setzt das modification date der Dateien auf ihr Aufnahmedatum.
    # Der Parameter -r benennt die Dateien um: Es wird dem Dateinamen das Aufnahmedatum im ISO8601-Format vorangestellt.
    /usr/local/bin/exiv2 -t -r'%Y%m%d_ :basename:' rename $(ls)
    
    # Die Bilder aus dem aktuellen _tmp Verzeichnis in das darüberliegende "MyPhotoStream" Verzeichnis verschieben
    find . -type f -exec mv "{}" .. \;
    
    # Abschließend die Bilder aus dem Photostream-Ordner löschen
    rm -r ~/Pictures/Photos\ Library.photoslibrary/Masters/*
    rm -r ~/Pictures/Photos\ Library.photoslibrary/Thumbnails/*
    
  4. photostream.sh Rechte setzen. Mit
    $ chmod 700 photostream.sh
    die Rechte der Shell-Datei auf “ausführbar” setzen.
  5. Automatisieren. Wir richten einen Daemon ein, der einmal pro Minute unser photostream.sh Skript aufruft. Auf diese Weise werden Bilder-Neuankömmlinge aus dem Photo Stream regelmässig und zeitnah aus dem Photos App Unterordner in unseren Zielordner überführt. Dazu wird eine Datei mit folgendem Inhalt an einem beliebigen Ort mit dem Namen com.NAME.photostream.plist angelegt. NAME kann frei gewählt werden.
    
    
    
    
       Label
       com.NAME.photostream
       ProgramArguments
       
           /Volumes/Macintosh HD/Users/USER/photostream.sh
       
       StartInterval
       60
    
    
    
    In der Datei ist NAME in <string>com.NAME.photostream</string> entsprechend des beim Anlegen der Datei gewählten Dateinamens zu ändern. Auch der Pfad /Volumes/Macintosh HD/Users/USER/photostream.sh muß so angepasst werden, dass er korrekt auf die photostream.sh Shell-Datei zeigt. Das StartInterval von 60 entspricht 60 Sekunden, d.h. das Skript wird einmal pro Minute aufgerufen. Wer weniger häufig nach neuen Bildern im Photo Stream nachschauen möchte, kann den Wert einfach nach oben setzen.
  6. Daemon aktivieren. Wir müssen dem Daemon/Agent manager launchd noch mitteilen, dass es einen neuen Daemon gibt, um den er sich kümmern soll. Das geschieht auf der Kommandozeile mit dem folgenden Befehl:
    $ launchctl load com.NAME.photostream.plist
    Auch hier ist NAME entsprechend zu ersetzen.

Fertig! Wenn’s erstmal läuft, läuft’s wie geschnitten Brot. Auch mit El Capitan und ohne AirDrop. 😉

Chrome Shortcut oder Tastenkombination um aktuelles Tab zu duplizieren

Zwei Lösungen, um ein Chrome-Tab per Tastenkombination zu Duplizieren. Schnell, sauber, effizient und ein Video gibt's auch noch.

Der übliche Weg, um ein Tab in Chrome zu duplizieren führt über einen Rechts-Klick auf das Tab und Auswahl des Popup-Menüpunktes “Duplicate”.

Wer als Tastatur-Universalhackspecht seine Finger aber lieber auf dem Keyboard belassen möchte, findet jeden Griff zur Maus nervig. Leider gibt es in Chrome keine eingebaute Tastenkombination, um das aktuelle Tab zu duplizieren.

Eine schnelle Variante, die allerdings kein 100%iges Duplikat erzeugt: CMD+L (aktiviert die URL-Zeile), dann CMD+Return. Zack! Schon wird das Tab geklont. Aber nur geklont, nicht echt dupliziert. Die Seite wird neu geladen, was beim Duplizieren nicht der Fall sein sollte. Weder die Position im Dokument noch die History (Back-Button) wird übertragen. Wer damit leben kann, ist mit dieser Lösung axellent bedient. Weitere Lösungsvorschläge im Geek TV Style liefert dieser Stackoverflow-Post.

Zweite Variante, ohne Hacken: Die Chrome Extension Duplicate Tab Shortcut Key installieren. So muß ‘ne Extension aussehen, dann klappt’s auch mit dem Nachbarn Duplizieren.

PHP: Mit Google Spreadsheet verbinden und Daten lesen oder schreiben

Eine Schritt für Schritt Anleitung, um mit PHP via OAuth2 auf Daten von Google Spreadsheets oder anderen Google Diensten zuzugreifen.

Man kann den Suchmaschinenmarktführer mögen oder auch nicht. Aber die Google Docs bieten etwas, das mit Excel, Word & Co. Stand heute nicht realisierbar ist: Mehrere Personen arbeiten gemeinsam an einem Dokument. In Echtzeit. Zu den gemeinsam verwaltbaren Dokumenten gehören aktuell:

  • Docs (Textdokumente)
  • Slides (Präsentationen)
  • Sheets (Tabellenkalkulationen)
  • Forms (Web-Formulare, bspw. für Befragungen)
  • Drawings (Konkurrenz für Microsofts Bitmap Programm, muahaha)
  • My Maps (Karten)

Natürlich ist der Funktionsumfang der einzelnen Tools nicht mit anderen Tools wie aus den Suiten von Open Office oder MS Office vergleichbar. Aber die echt kollaborative Zusammenarbeit ist ein Killer Feature und eröffnet interessante Use Cases.

Google Docs Daten automatisiert verarbeiten

Docs, Slides & Co. werden in der Regel im Browser bearbeitet. Das wird für viele Anwendungsfälle genügen. Was aber, wenn Daten sowohl im Browser gepflegt als aber auch durch Software automatisiert verarbeitet werden sollen?

Google stellt umfangreiche Schnittstellen-Dokumentationen für verschiedene APIs zur Verfügung, die den Zugriff per .net, Java oder PHP beschreiben. Durch eine unlängst erfolgte Umstellung auf oAuth2 ist jedoch die Authentisierung für den softwaregesteuerten Zugriff komplexer geworden. Deutlich komplexer.

Wie geht dem?

Die Umstellung auf oAuth2 hat es in sich, denn viele selbstgeschriebene Skripte laufen seitdem nicht mehr. Während die alte Authentisierung mit Username-/Password-Kombination vergleichsweise simpel war, erfordert der Zugriff via oAuth2 mehr Aufwand.

Viele Nutzer im Netz suchen nach entsprechenden Lösungen, wobei konkrete Schritt-für-Schritt-Anleitungen, die 100%ig erfolgreich sind, fehlen. Zusätzlich scheint es nur im englischsprachigen Raum überhaupt Hilfe zu geben. Wenn man aber erst einmal genug Quellen in einen Topf geworfen hat, kommt am Ende sogar eine Suppe Lösung raus. Hier Schritt für Schritt, wie es funktionieren kann. (Viele Wege, Rom, blabla)

So geht dem!

Wir legen zu Testzwecken ein Google (Spread)Sheet an.
Test Google Spreadsheet Reiter

Das Spreadsheet heißt “Test-O-Mat” und besteht aus den zwei Worksheets “Argl” und “Wargl”.

Der Weg zu den Daten mit PHP: Schritt für Schritt

  1. Verzeichnis anlegen. Wir legen irgendwo ein passendes Verzeichnis für unser Testprojekt an, bspw. im Home-Verzeichnis des eingeloggten Users und wechseln hinein.
    $ mkdir ~/oauth && cd ~/oauth
  2. Composer installieren. Wir brauchen den PHP Dependency Manager “Composer”. Dieser lässt sich am einfachsten mit dem folgenden Befehl auf der Kommandozeile installieren. Das setzt natürlich eine funktionsfähige lokale PHP-Installation voraus.
    $ curl -sS https://getcomposer.org/installer | php

    Wenn die Installation erfolgreich verläuft, sieht das in etwa so aus:

    #!/usr/bin/env php
    All settings correct for using Composer
    Downloading...
    
    Composer successfully installed to: <Pfad>/oauth/composer.phar
    Use it: php composer.phar
    $
    

    Es wurde eine composer.phar Datei erstellt – ein PHp ARchive, das nach dem nächsten Schritt zum Einsatz kommt.

  3. composer.json erstellen. Für die Arbeit mit den Google APIs werden bestimmte PHP-Libraries benötigt. Der im vorherigen Schritt installierte Dependency Manager entledigt uns der Bürde, diese Libraries manuell zu verwalten. Aber er muss wissen, welche Libraries wir genau benötigen. Das bekommt er über eine projektbezogene composer.json Datei mitgeteilt. Dafür im aktuellen Verzeichnis eine composer.json Datei mit folgendem Inhalt anlegen.
    {
      "require": {
        "asimlqt/php-google-spreadsheet-client": "2.2.*",
        "google/apiclient": "1.0.*@beta"
      }
    }
    
  4. Libraries installieren. Mit dem folgenden Befehl wird der Composer gestartet. Er lädt alle benötigten Libraries von den zugehörigen Servern und installiert die Library-Dateien im aktuellen Verzeichnis.
    $ php composer.phar install

    Wenn’s gut läuft, sieht das wie folgt aus.

    Loading composer repositories with package information
    Installing dependencies (including require-dev)
      - Installing asimlqt/php-google-spreadsheet-client (2.2.4)
        Downloading: 100%
    
      - Installing google/apiclient (1.0.6-beta)
        Downloading: 100%
    
    Writing lock file
    Generating autoload files
    $
    

    Verzeichnis und Dateien nach den ersten Schritten Nach der erfolgreichen Ausführung des Composers sollte sich ein neues Unterverzeichnis “vendor” im aktuellen Verzeichnis befinden. Zusätzlich die Dateien composer.phar (Composer Dependency Manager), composer.lock (Finger weg!) und composer.json.

  5. Credentials für oAuth2 Authentisierung erstellen. Wir benötigen Authentisierungs-Credentials, die mit der Google Developers Console generiert werden. Dies erfordert, wie alles bei Google, einen Google Account. Falls noch nicht vorhanden, Google Account anlegen und dann bei der Google Developers Console registrieren. Nach dem Login empfängt uns eine karge Benutzeroberfläche.
    Google Developers Console
    Zur Erstellung der Credentials für unser PHP-Skript wie folgt vorgehen.

    1. Im Hauptmenü “APIs & auth” wählen. Dort “Credentials”.
    2. Der Datenbereich zeigt ein Drop-Down-Menü. Dort “Service account” wählen.
      Credentials Service Account
    3. Es folgt eine Auswahl zum gewünschten Keytype. “P12” anklicken und den Button “Create” drücken. Der Browser speichert daraufhin ein Key-Datei “API Project-xxxxxxxxxx.p12”. Diese in’s Projektverzeichnis kopieren. Gleichzeitig wird ein Passwort im Browser angezeigt. Dieses notieren, wir brauchen es später noch.
    4. Im Datenbereich wird daraufhin eine Übersicht aller Credentials angezeigt. Gibt es mehrere Service Account Credentials, so steht unser neu angelegter ganz unten in der Liste. Die zugehörige E-Mail-Adresse anklicken und die auf dem folgenden Screen angezeigte lange, kryptische Client ID sowie die ebenso lange und ebenso kryptische E-Mail-Adresse notieren. Brauchen wir später noch.
      Credentials Service Account

    Mehr gibt es in der Developers Console nicht zu tun.

  6. Spreadsheet freigeben. Das Google Spreadsheet “Test-O-Mat” muss für den soeben angelegten Service Account freigegeben werden, damit über diesen auf das Spreadsheet zugegriffen werden kann. Dazu verwenden wir die zuvor notierte E-Mail-Adresse aus der Google Developers Console: Im Google Spreadsheet oben rechts auf den Share/Teilen Button klicken. Daraufhin öffnet sich ein Popup-Fenster mit Eingabefeld. Dort die E-Mail-Adresse hineinkopieren, die Option “Notify people via E-Mail” abwählen und “Send” drücken.
  7. PHP Code für den Spreadsheet Zugriff erstellen. Now for the fun part, falls das noch nicht genug Spaß war. Eine frische index.php im Projektverzeichnis anlegen und im Editor öffnen. Dort den folgenden Kode einfügen und G_CLIENT_ID, G_CLIENT_EMAIL sowie G_CLIENT_KEY_PATH durch die eigenen Credentials ersetzen. Ggfs. ist auch das Passwort durch das eigene zu ersetzen, aber ich glaube, dass beim P12-Keyfile stets “notasecret” gewählt wird.
    setApplicationName( 'Test-O-Mat' );
    $client->setClientId( G_CLIENT_ID );
    $client->setAssertionCredentials( new Google_Auth_AssertionCredentials(
        G_CLIENT_EMAIL,
        array( 'https://spreadsheets.google.com/feeds', 'https://docs.google.com/feeds' ),
        file_get_contents( G_CLIENT_KEY_PATH ),
        G_CLIENT_KEY_PW
    ) );
    $client->getAuth( )->refreshTokenWithAssertion( );
    $objToken = json_decode( $client->getAccessToken( ) );
    $accessToken = $objToken->access_token;
    
    $serviceRequest = new GoogleSpreadsheetDefaultServiceRequest( $accessToken );
    GoogleSpreadsheetServiceRequestFactory::setInstance( $serviceRequest );
    
    $spreadsheetService = new GoogleSpreadsheetSpreadsheetService( );
    $spreadsheetFeed = $spreadsheetService->getSpreadsheets( );
    echo "
    ";
    foreach( $spreadsheetFeed as $spreadsheet ) {
      echo $spreadsheet->getTitle( )."n";
      $worksheetFeed = $spreadsheet->getWorksheets( );
      foreach( $worksheetFeed as $worksheet ) {
        echo "|n+-" . $worksheet->getTitle( ) . "n";
      }
    }
    echo "</pre>";
    ?>
    

    Das Skript authentisiert sich via OAuth2, startet dann einen Service Request ggü. Google Spreadsheets, holt sich eine Liste aller(!) Spreadsheets, die mit der (kryptischen) E-Mail-Adresse geteilt wurden, iteriert über diese Liste und gibt für jedes Spreadsheet die Namen aller enthaltenen Worksheets aus.

    Wir haben nur das Spreadsheet "Test-O-Mat" für die E-Mail-Adresse freigegeben. Daher sollte der Browser eine Ausgabe wie die Folgende produzieren.

    Test-O-Mat
      |
      +-Argl
      |
      +-Wargl
    

Fazit

Wenn die Ausgabe wie zuletzt gezeigt war, dann ist es Zeit für einen Glückwunsch-Schokohasen. Die Authentisierung läuft, der Zugriff auf beliebige Spreadsheets ist möglich. Lesen und Schreiben von Daten is left as an excercise to the reader.

MacOS: Neuen “Öffnen mit”-Service zum Dienste-Menü hinzufügen

Eine Datei oder einen Ordner per Rechtsklick im MacOS-Lieblingsprogramm öffnen? Das geht in wenigen Schritten mit dem Automator.

Der Rechtsklick auf eine Datei oder einen Ordner im Finder öffnet das Kontextmenü. Dortens, ganz unten, befindet sich das Dienste-Untermenü, in dem Applikationen zusätzliche Funktionalitäten unterbringen können. Der Viren-Scanner ClamXav, jahrelang kostenlos und nun leider kostenpflichtig, nistet sich bspw. dort ein und ermöglicht auf diese Weise das Scannen einzelner Dateien.

das Rechtsklick-Dienste-Menü

Dienst-Menü erweiterbar

Dieses Service-Menü kann mit eigenen Diensten erweitert werden. Hier ein Beispiel für die Erstellung eines Dienste, der das Öffnen von Dateien oder Ordnern in Sublime Text ermöglicht. Dazu verwenden wir den Automator, eine Applikation, die jeder MacOS-Installation von Haus aus beiliegt.

Schritt-für-Schritt zum neuen Dienst

  1. Automator starten. Entweder Finder öffnen, dann CMD+Shift+A und in der Dateiliste die Automator.app Doppelklicken. Oder Spotlight mit CMD+Space aufrufen, “auto” tippen und Return. (Unterstellt, dass Spotlight den automator vorschlägt.)
  2. Automator-Typ wählen. Im Popdown-Fenster “Service” auswählen, dann mit dem Choose-Button bestätigen.
    Service im Automator wählen
  3. Service receives und Action wählen. Im “Service receives selected”-Drop-Down “files or folders” wählen.
    Im Suchfeld oben links “run shell” eingeben. In der darunterliegenden Liste an Aktionen sollte nur noch “Run Shell Script” erscheinen. Diese Aktion per Drag’n’Drop in das Workflow-Feld rechts ziehen.
    Services receives und Run Shell Skript Aktion
  4. Pass input und Shell Skript. Die Datei- und Ordner-Namen sollen als Kommandozeilenargumente an das Shell Skript übergeben werden. Dafür im “Pass input”-Drop-Down den Wert “as arguments” wählen.
    Anschliessend noch in das Eingabefenster der “Run Shell Skript”-Aktion den Pfad zum Sublime Text-Executable gefolgt von -n "$@" eintragen.
    Argumente und auszuführende Datei
  5. Den neuen Service mit CMD+S unter einem beliebigen Namen speichern, z.B. “Open in Sublime3”.

Fertig! Wer alles richtig gemacht hat, sieht im Finder nach Rechtsklick auf eine Datei oder einen Ordner “Open in Sublime3” als neuen Eintrag im Services-Untermenü, like diz:

fertiger Dienst im Finder

PS für Neunmalkluge

Ich höre sie schon rufen: “Was soll das denn mit der ‘Run Shell Script’-Aktion? Das geht doch alles viel einfacher mit ‘Open Finder Items’!” Stimmt. Und stimmt nicht. Der Ansatz mit “Open Finder Items” ist in diesem Artikel beschrieben, allerdings werden die Dateien/der Ordner damit in den Projektbaum des aktuell geöffneten Projektes eingefügt. Die hier beschriebene Verwendung von “Run Shell Script” verhindert dies und öffnet Dateien und Ordner in einem neuen Workspace in Sublime. Besser ist das.