简体   繁体   中英

How to include terminal-notifier when packaging with py2app

I am making an app in python on mac osx. I am using py2app for making myapp.app from myapp.py python script file and setup.py. In my myapp.py code, I am using terminal-notifier as

def notify(title, subtitle, message):
    t = '-title {!r}'.format(title)
    s = '-subtitle {!r}'.format(subtitle)
    m = '-message {!r}'.format(message)
    os.system('terminal-notifier {}'.format(' '.join([m, t, s])))

notify(
    title    = 'Title message',
    subtitle = 'with python',
    message  = 'Validating user'
)

It is working fine as showing notification after installing as sudo gem install terminal-notifier . terminal-notifier is present in my system in location /Library/Ruby . My problem is how to include this in py2app for developing my app, as py2app is not able to include terminal-notifier in myapp.app . My setup.py is

from setuptools import setup

APP=['myapp.py']
DATA_FILES= [('',['config.cfg'])]
OPTIONS={'iconfile':'cc.icns','argv_emulation': True,'plist':{'CFBundleShortVersionString':'1.0'}}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app']
    )   

It should be possible to include the script as a data file (it then ends up in the 'Resources' folder of the application, which is the current working directory when the app is started)

That said, I have no experience with terminal-notifier at all, and very little experience with Ruby, and don't know if just copying the script file will be enough to end up with a working script (due to dependencies)

BTW Terminal notifier appears to be a tool to send messages to the notification center: https://github.com/julienXX/terminal-notifier . That's something you could also do using PyObjC.

I had the same issue and could not figure out a perfect resolution but this workaround worked for me...

Right click on the app and select "Show Package Contents" and then select the "Contents" folder. Inside the "Contents" folder is another folder called "MacOS" open that folder and locate the .exe file for your app. You can create an alias for that .exe and drag it anywhere (i,e Desktop or Applications). Double click on the alias of your .exe to start your app and notifications will work (granted a terminal window will open every time you run the exe).

Terminal-notifier is being packaged as it works perfectly when you run the exe but for some reason it does not work with the app generated via py2app!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM