Skip to content

Commit

Permalink
mojave fix
Browse files Browse the repository at this point in the history
  • Loading branch information
milgra committed Jan 6, 2019
1 parent 7991e8e commit b9f22bb
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 25 deletions.
65 changes: 43 additions & 22 deletions MacMediaKeyForwarder/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -335,31 +335,52 @@ - ( void ) applicationDidFinishLaunching : ( NSNotification*) theNotification
[self updateOptionState];

eventPort = CGEventTapCreate( kCGSessionEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, CGEventMaskBit(NX_SYSDEFINED), tapEventCallback, (__bridge void * _Nullable)(self));
eventPort = CGEventTapCreate( kCGSessionEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, NX_SYSDEFINEDMASK, tapEventCallback, (__bridge void * _Nullable)(self));
if ( eventPort == NULL )
{
eventPort = CGEventTapCreate( kCGSessionEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, NX_SYSDEFINEDMASK, tapEventCallback, (__bridge void * _Nullable)(self));
}

// Check if permission is granted to send AppleEvents to the running app target, and prompt if not set
if ( @available(macOS 10.14, *) )
if ( eventPort != NULL )
{

iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
SpotifyApplication *spotify = [SBApplication applicationWithBundleIdentifier:@"com.spotify.client"];

if ( spotify != nil )
{
NSAppleEventDescriptor *targetAppEventDescriptor = [NSAppleEventDescriptor descriptorWithBundleIdentifier:@"com.spotify.client"];
AEDeterminePermissionToAutomateTarget([targetAppEventDescriptor aeDesc], typeWildCard, typeWildCard, true);
}

if ( iTunes != nil )
{
NSAppleEventDescriptor *targetAppEventDescriptor = [NSAppleEventDescriptor descriptorWithBundleIdentifier:@"com.apple.iTunes"];
AEDeterminePermissionToAutomateTarget([targetAppEventDescriptor aeDesc], typeWildCard, typeWildCard, true);
}
}

eventPortSource = CFMachPortCreateRunLoopSource( kCFAllocatorSystemDefault, eventPort, 0 );

[self startEventSession];
// Check if permission is granted to send AppleEvents to the running app target, and prompt if not set
if ( @available(macOS 10.14, *) )
{

iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
SpotifyApplication *spotify = [SBApplication applicationWithBundleIdentifier:@"com.spotify.client"];

if ( spotify != nil )
{
NSAppleEventDescriptor *targetAppEventDescriptor = [NSAppleEventDescriptor descriptorWithBundleIdentifier:@"com.spotify.client"];
AEDeterminePermissionToAutomateTarget([targetAppEventDescriptor aeDesc], typeWildCard, typeWildCard, true);
}

if ( iTunes != nil )
{
NSAppleEventDescriptor *targetAppEventDescriptor = [NSAppleEventDescriptor descriptorWithBundleIdentifier:@"com.apple.iTunes"];
AEDeterminePermissionToAutomateTarget([targetAppEventDescriptor aeDesc], typeWildCard, typeWildCard, true);
}
}

eventPortSource = CFMachPortCreateRunLoopSource( kCFAllocatorSystemDefault, eventPort, 0 );

[self startEventSession];

}
else
{

NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:@"Error"];
[alert setInformativeText:@"Cannot start event listening. Please add Mac Media Key Forwarder to System Preferences/Security and Privacy/Privacy/ Accessibility and Automation submenus"];
[alert addButtonWithTitle:@"Ok"];
[alert runModal];

exit(0);

}

}

- ( void ) startEventSession
Expand Down
4 changes: 2 additions & 2 deletions MacMediaKeyForwarder/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.1</string>
<string>2.2</string>
<key>CFBundleVersion</key>
<string>3</string>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key>
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ Thank you!!!

---

**What's new in version 2.1 :**
**What's new in version 2.2 :**
- MacOS Mojave 10.14.2 fix, showing notification pop-up if tap cannot be created

*What's new in version 2.1 :*
- app brings up permission popups if permission is not granted for Accessibility and Automation Target

What's new in version 2.0 :
Expand Down

0 comments on commit b9f22bb

Please sign in to comment.