macOS用のユーティリティ
macOS関連のコマンドをどうしても覚えられない。たいていはEmacsから起動するため、Emacsから呼び出しやすいようなユーティリティを実装する。今のところ、以下の機能を提供している。
- macOSのアプリケーションをEmacsから起動する。
- オーディオデバイスの一覧を表示する。
- アプリケーションのバンドルIDを表示する。
- マイクの音声をffmpegで録音する
;;; macos --- macOS Utility. -*- lexical-binding: t -*-
;; Copyright (C) 2024 TakesxiSximada
;; Author: TakesxiSximada <[email protected]>
;; Maintainer: TakesxiSximada <[email protected]>
;; Version: 3
;; Package-Version: 20240321.0000
;; Package-Requires: ((emacs "29.1"))
;; Date: 2024-03-21
;; This file is not part of GNU Emacs.
;;; License:
;; This program is free software: you can redistribute it and/or
;; modify it under the terms of the GNU Affero General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; Affero General Public License for more details.
;; You should have received a copy of the GNU Affero General Public
;; License along with this program. If not, see
;; <https://www.gnu.org/licenses/>.
;;; Code:
(defcustom macos-app-path-list '("/Applications"
"/Applications/Utilities"
"/System/Applications"
"/System/Applications/Utilities")
"macOS Application path list"
:group 'macos
:type '(repeat directory))
(defcustom macos-app-buffer-name "*macOS App*"
"Buffer name of open command"
:group 'macos
:type 'string)
(defvar macos-app-list nil)
(defun macos-app-refresh ()
(interactive)
(setq macos-app-list
(apply #'append
(mapcar (lambda (application-path)
(mapcar (lambda (name) (concat (directory-file-name application-path) "/" name))
(directory-files application-path nil ".app")))
macos-app-path-list))))
;;;###autoload
(defun macos-app (&optional app)
"Start macOS application from Emacs"
(interactive (list (completing-read "Application: " macos-app-list)))
(make-process :name "*App*"
:buffer (get-buffer-create macos-app-buffer-name)
:command `("open" "-g" ,app)
))
;;;###autoload
(defun macos-app-new (&optional app)
"Start macOS application new instance from Emacs"
(interactive (list (completing-read "Application: " macos-app-list)))
(make-process :name "*App*"
:buffer (get-buffer-create macos-app-buffer-name)
:command `("open" "-g" "--new" ,app)
))
;;;###autoload
(defcustom macos-list-audio-devices-buffer-name "*macOS Audio Device List*"
"Audio Device List Buffer Name"
:group 'macos
:type 'string)
;;;###autoload
(defun macos-list-audio-devices ()
"Display Audio Devices"
(interactive)
(make-process :name "*macOS Audio Device List*"
:buffer (get-buffer-create macos-list-audio-devices-buffer-name)
:command '("/usr/sbin/system_profiler" "SPAudioDataType"))
(switch-to-buffer macos-list-audio-devices-buffer-name))
;;;###autoload
(defun macos-show-bundle-id (app-name)
"Display Application bundle id"
(interactive "sApplication: ")
(async-shell-command (format "osascript -e 'id of app \"%s\"'" app-name)))
;;;###autoload
(defun macos-record-microphone-audio-with-ffmpeg ()
"Record microphone audio with ffmpeg"
(interactive)
(async-shell-command "ffmpeg -f avfoundation -i \":1\" output.wav"))
;;;###autoload
(defun macos-list-devices-with-ffmpeg ()
"Record microphone audio with ffmpeg"
(interactive)
(async-shell-command "ffmpeg -f avfoundation -list_devices true -i \"\""))
(provide 'macos)
;;; macos.el ends here