Replaced notification with PYNC #1

Open
wants to merge 2 commits into
from

Conversation

Projects
None yet
9 participants
@jayzawrotny

I couldn't get the notifications to fire. After doing some research I found http://objcolumnist.com/2012/07/25/os-x-mountain-lion-api-highlights/ which states: "It is important to note that only signed Apps (Gatekeeper, MAS etc) can post notifications."

However my solution is not the best fix. It uses pync https://github.com/SeTeM/pync which is a Python wrapper for terminal-notifier. If terminal-notifier is not present then nothing happens, else it works just fine.

Hope this helps. Thanks for writing this software!

Review on Reviewable

jayzawrotny added some commits Jan 30, 2013

Added pync locally.
Signed-off-by: Jay <jayzawrotny@gmail.com>
@dbader

This comment has been minimized.

Show comment
Hide comment
@dbader

dbader Jan 30, 2013

Owner

Nice man, thanks for your effort :))

I'm not really convinced though that an added dependency on psync + terminal-notifier is the best solution for this problem. The vanilla system version of Python on Mountain Lion should be codesigned correctly and therefore allowed to post NSUserNotifications.

From what I gathered, notifications seem to work fine for most people. Then again you're already the second person that reports that there is some issue with them ;). The issue seems to show up more often on developer's systems. Maybe there is some problem with the system (codesigned) version of Python getting replaced by another install that is not codesigned.

I think we should investigate more in this direction... I definitely appreciate your work on this though. I've updated my blog article with a link to your code (and homepage).

Cheers,
Daniel

Owner

dbader commented Jan 30, 2013

Nice man, thanks for your effort :))

I'm not really convinced though that an added dependency on psync + terminal-notifier is the best solution for this problem. The vanilla system version of Python on Mountain Lion should be codesigned correctly and therefore allowed to post NSUserNotifications.

From what I gathered, notifications seem to work fine for most people. Then again you're already the second person that reports that there is some issue with them ;). The issue seems to show up more often on developer's systems. Maybe there is some problem with the system (codesigned) version of Python getting replaced by another install that is not codesigned.

I think we should investigate more in this direction... I definitely appreciate your work on this though. I've updated my blog article with a link to your code (and homepage).

Cheers,
Daniel

@jayzawrotny

This comment has been minimized.

Show comment
Hide comment
@jayzawrotny

jayzawrotny Jan 30, 2013

Daniel,

You're right. PYNC + terminal-notifier is definitely not the best, but between that or it not working at all I would prefer the latter.

That is interesting that it is working on other people's systems. When you run "python" in terminal, what does it greet you with?

Python 2.7.2 (default, Jun 20 2012, 16:23:33) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Daniel,

You're right. PYNC + terminal-notifier is definitely not the best, but between that or it not working at all I would prefer the latter.

That is interesting that it is working on other people's systems. When you run "python" in terminal, what does it greet you with?

Python 2.7.2 (default, Jun 20 2012, 16:23:33) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
@dbader

This comment has been minimized.

Show comment
Hide comment
@dbader

dbader Feb 2, 2013

Owner

Output of python:

Python 2.7.2 (default, Jun 20 2012, 16:23:33) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin

Output of codesign --verbose --verify /usr/bin/python:

/usr/bin/python: valid on disk
/usr/bin/python: satisfies its Designated Requirement

We seem to be on the same Python version.

Owner

dbader commented Feb 2, 2013

Output of python:

Python 2.7.2 (default, Jun 20 2012, 16:23:33) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin

Output of codesign --verbose --verify /usr/bin/python:

/usr/bin/python: valid on disk
/usr/bin/python: satisfies its Designated Requirement

We seem to be on the same Python version.

@jondashkyle

This comment has been minimized.

Show comment
Hide comment
@jondashkyle

jondashkyle Apr 2, 2013

Was having similar problems; your fix appears to work for me, Jay. Thanks!

Was having similar problems; your fix appears to work for me, Jay. Thanks!

@ranman

This comment has been minimized.

Show comment
Hide comment
@ranman

ranman May 22, 2013

Contributor

May I suggest an alternative fix for people with multiple python installations?

/usr/bin/python timer.py {query} > /dev/null 2>&1 &
instead of
python timer.py {query} > /dev/null 2>&1 &

this is naively suggested in the hopes that no one on mountain lion actually replaced the default system install of python.

Contributor

ranman commented May 22, 2013

May I suggest an alternative fix for people with multiple python installations?

/usr/bin/python timer.py {query} > /dev/null 2>&1 &
instead of
python timer.py {query} > /dev/null 2>&1 &

this is naively suggested in the hopes that no one on mountain lion actually replaced the default system install of python.

@dbader

This comment has been minimized.

Show comment
Hide comment
@dbader

dbader May 22, 2013

Owner

I've made progress on the "notifications not displaying" issue. Code-signing seems to make no difference (though it is still a good idea to go with the system default Python in /usr/bin/python, as recommended by @ranman).

The trouble is that, in order to post NSUserNotifications, binaries must be packaged as application bundles (StackOverflow Question). This requirement seems to have been added by Apple lately, as the original extension code worked fine for me.

Delivering a proper application bundle is obviously very difficult (impossible?) to do in an Alfred extension. Luckily, this very smart man, @norio-nomura, found a solution: Use method swizzling to make [NSBundle bundleIdentifier] return a fake bundle identifier (see https://github.com/norio-nomura/usernotification) :-)

I've implemented this in af464b4. So far it's working well. Could you please check if it works on your machines? Thanks!

I'm pushing the updated .alfredextension and .alfredworkflow files in a minute.

Owner

dbader commented May 22, 2013

I've made progress on the "notifications not displaying" issue. Code-signing seems to make no difference (though it is still a good idea to go with the system default Python in /usr/bin/python, as recommended by @ranman).

The trouble is that, in order to post NSUserNotifications, binaries must be packaged as application bundles (StackOverflow Question). This requirement seems to have been added by Apple lately, as the original extension code worked fine for me.

Delivering a proper application bundle is obviously very difficult (impossible?) to do in an Alfred extension. Luckily, this very smart man, @norio-nomura, found a solution: Use method swizzling to make [NSBundle bundleIdentifier] return a fake bundle identifier (see https://github.com/norio-nomura/usernotification) :-)

I've implemented this in af464b4. So far it's working well. Could you please check if it works on your machines? Thanks!

I'm pushing the updated .alfredextension and .alfredworkflow files in a minute.

@dbader

This comment has been minimized.

Show comment
Hide comment
@dbader

dbader May 22, 2013

Owner

Ok, the changes are live in f7873bd.

Owner

dbader commented May 22, 2013

Ok, the changes are live in f7873bd.

@dbader dbader referenced this pull request May 22, 2013

Open

Nothing happens :-/ #2

@norio-nomura

This comment has been minimized.

Show comment
Hide comment
@norio-nomura

norio-nomura May 27, 2013

I don't know about .alfredextension, but I know NSUserNotificationCenter needs runloop until finish delivering a notification.

I don't know about .alfredextension, but I know NSUserNotificationCenter needs runloop until finish delivering a notification.

@dbader dbader referenced this pull request Jul 30, 2013

Closed

Notification Icon #6

@krid78

This comment has been minimized.

Show comment
Hide comment
@krid78

krid78 Oct 27, 2013

Hmm ... While the extension was working well for me on ML, with Mavericks it stopped sending notifications. I use the python version bundled with Mavericks.

Any one else seeing this problem?

krid78 commented Oct 27, 2013

Hmm ... While the extension was working well for me on ML, with Mavericks it stopped sending notifications. I use the python version bundled with Mavericks.

Any one else seeing this problem?

@tfeldmann

This comment has been minimized.

Show comment
Hide comment
@tfeldmann

tfeldmann Jan 1, 2014

Yes, notifications don't work on Mavericks

Yes, notifications don't work on Mavericks

@rafaelrinaldi

This comment has been minimized.

Show comment
Hide comment
@rafaelrinaldi

rafaelrinaldi Feb 9, 2014

Having the same issue on Mavericks. It was working for a while but then it stopped. I can hear the sound when a task is done but no notifications is being fired.

Having the same issue on Mavericks. It was working for a while but then it stopped. I can hear the sound when a task is done but no notifications is being fired.

@dbader

This comment has been minimized.

Show comment
Hide comment
@dbader

dbader Feb 13, 2014

Owner

Thanks for raising this. Everything works fine for me on Mavericks but I'll look into it. Might have something to do with me running Python installed via Homebrew.

Owner

dbader commented Feb 13, 2014

Thanks for raising this. Everything works fine for me on Mavericks but I'll look into it. Might have something to do with me running Python installed via Homebrew.

@rafaelrinaldi

This comment has been minimized.

Show comment
Hide comment
@rafaelrinaldi

rafaelrinaldi Feb 13, 2014

@dbader Yeah, it might be. I'm running the one who comes with Mavericks which is 2.7.5.

Let me know if you need any help.

@dbader Yeah, it might be. I'm running the one who comes with Mavericks which is 2.7.5.

Let me know if you need any help.

@dbader

This comment has been minimized.

Show comment
Hide comment
@dbader

dbader May 18, 2014

Owner

I'm linking #7 here because it could be a possible workaround for this issue.

Owner

dbader commented May 18, 2014

I'm linking #7 here because it could be a possible workaround for this issue.

@rhacker

This comment has been minimized.

Show comment
Hide comment
@rhacker

rhacker Jun 26, 2014

I still have the same problem on ML. Do we agree on any solution yet ?

rhacker commented Jun 26, 2014

I still have the same problem on ML. Do we agree on any solution yet ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment