Notify using Notification Center when the execution environment is macOS in Python

Check the OS running the script with platform.system () and throw ʻosascript -e'display notification" hoge "'to the shell. For macOS,platform.system ()will be replaced with'Darwin'`.

python


import os,platform

def main():
  if platform.system() == 'Darwin':
    os.system("osascript -e 'display notification \"This is a mac\"'")

if __name__ == '__main__':
  main()

References:

--platform – Access system version information --Python Module of the Week -Notify Mac Notification Center from Python --Qiita

Recommended Posts

Notify using Notification Center when the execution environment is macOS in Python
Initial settings when using the foursquare API in python
Solve the Japanese problem when using the CSV module in Python.
Precautions when using pit in Python
When using regular expressions in Python
[Python] Execution time when a function is entered in a dictionary value
Build Python environment on Ubuntu (when pip is not the default)
What to do when the value type is ambiguous in Python?
Write a script in Shell and Python to notify you in Slack when the process is finished
Try using the Wunderlist API in Python
Python development environment for macOS using venv 2016
Periodic execution processing when using tkinter [Python3]
Try using the Kraken API in Python
Using venv in Windows + Docker environment [Python]
Tweet using the Twitter API in Python
What is "mahjong" in the Python library? ??
When the target is Ubuntu 16.04 in Ansible
Parallel task execution using concurrent.futures in Python
Introduced sip-4.14 in python3.2.2 environment with MacOS 10.7.4
What to do when the warning "The environment is in consistent ..." appears in the Anaconda environment
Switch the module to be loaded for each execution environment in Python
A useful note when using Python for the first time in a while
How to automatically notify by phone when the python system is down
A story when a directory is buggy with the django-admin start project command in a virtual environment using Pipenv
CERTIFICATE_VERIFY_FAILED in Python 3.6, the official installer for macOS
Prepare the execution environment of Python3 with Docker
What is wheezy in the Docker Python image?
Execution order when multiple context managers are specified in the Python with statement
About the difference between "==" and "is" in python
Install the python package in an offline environment
Precautions when installing packages in the conda environment
Notify Notification Center
[Environment construction] Dependency analysis using CaboCha in Python 2.7
[For beginners] Unexpected behavior if "\" is included when setting the path in Python
Pre-process the index in Python using Solr's ScriptUpdateProcessor
Notify slack when the switch sales page is updated ~ slack bot development with python ③ ~
Use pydantic when reading environment variables in Python
Try using the DropBox Core API in Python
I checked the reference speed when using python list, dictionary, and set type in.
Investigate the cause when an error is thrown when python3.8 is not found when using lambda-uploader with python3.8
There is a pattern that the program did not stop when using Python threading
Check if the string is a number in python
When the selected object in bpy.context.selected_objects is not returned
[AWS IoT] Register things in AWS IoT using the AWS IoT Python SDK
Determine the threshold using the P tile method in python
Use the CASA Toolkit in your own Python environment
Embedding in datetime when only the time is known
Reproduce the execution example of Chapter 4 of Hajipata in Python
How to exit when using Python in Terminal (Mac)
Build a Python development environment using pyenv on MacOS
Using the National Diet Library Search API in Python
Reproduce the execution example of Chapter 5 of Hajipata in Python
Using the LibreOffice app in Python (1) Where are the macros?
virtual environment in python
Development environment in Python
Use Heroku in python to notify Slack when a specific word is muttered on Twitter
Correspondence when an alert is issued by the workon command after installing virtualenv (MacOS10.10 + Python3.4)
[RHEL7 / CentOS7] LWP execution error in the environment where Perl is installed with the yum command
Measure the execution result of the program in C ++, Java, Python.
Check the operation of Python for .NET in each environment
Commands often used in the development environment during Python implementation