【问题标题】:Changing Mac volume to a variable in terminal将 Mac 音量更改为终端中的变量
【发布时间】:2018-04-27 23:09:10
【问题描述】:

我正在尝试创建一个 shell 脚本,在其中将音量更改为最大,使用 Say 命令,然后将音量改回。到目前为止,我能够将旧音量保存为变量,将音量更改为最大并使用 say 命令。我遇到的唯一麻烦是将音量更改为变量值。

我有什么:

#!/bin/bash

VOL=$(osascript -e 'output volume of (get volume settings)')
osascript -e 'set Volume 100'
say Hello 
osascript -e "set Volume $VOL"

【问题讨论】:

    标签: macos shell terminal sh


    【解决方案1】:

    出于某种原因,set Volume x 使用 0 到 7 的体积比例,而 output volume of (get volume settings) 使用 0 到 100 的比例。您可以乘以 0.07,但有一个更简单的解决方案,Antal Spector-Zabusky 指出:使用set volume output volume n,它使用0-100的比例。

    vol=$(osascript -e 'output volume of (get volume settings)')
    osascript -e "set volume output volume 100"
    #say "Hello"
    osascript -e "set volume output volume $vol"
    

    【讨论】:

      猜你喜欢
      • 2018-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-10
      • 2015-10-01
      • 2020-09-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多