Created
March 30, 2012 01:38
-
-
Save frodwith/2245615 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use warnings; | |
use strict; | |
my %keys = ( esc => 53, tab => 48, space => 49); | |
my %mt = (m => 'command', 'o' => 'option', c => 'control', s => 'shift'); | |
my @mods = @ARGV; | |
my $key = pop @mods; | |
@mods = grep {defined} map { $mt{$_} } @mods; | |
my $mawd = ''; | |
if (@mods) { | |
$mawd = join ', ', map { "$_ down" } @mods; | |
$mawd = "using {$mawd}"; | |
} | |
my $special = $keys{$key}; | |
my $stroke = $special ? "key code $special" : qq'keystroke "$key"'; | |
my $script = <<"SCRIPT"; | |
tell application "System Events" | |
$stroke $mawd | |
end tell | |
SCRIPT | |
print $script; | |
open my $pipe, '|-', 'osascript'; | |
print {$pipe} $script; | |
close $pipe; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment