【问题标题】:Applescript output reading problem when embedded within python嵌入python时Applescript输出读取问题
【发布时间】:2019-06-21 07:17:17
【问题描述】:

我正在尝试制作一个可在 MacOS 上与 iTunes 一起使用的 python 应用程序,并根据播放器当前是否正在播放进行更改。我有一个 AppleScript 通过一个布尔值来判断它是否正在播放,但是当我尝试使用 python 读取它时,它不能与 python 一起使用。与字符串相同。

我尝试改用字符串,但也没有用。

def Update(self):
        osascript.run(self.applescript, background=True)
        self.proc = Popen(['osascript', '-'], stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)
        self.appscripPlayingOutput, error = self.proc.communicate(self.applescriptIsPlaying)
        print(self.appscripPlayingOutput)
        self.boolisPlay = self.str2bool(self.appscripPlayingOutput)
        print(self.boolisPlay)
        if self.boolisPlay == False:
            self.playing = False
            print("is paused")
        else:
            self.playing = True
            print("is playing")
        self.musicImage = Image.open(self.pathToAlbumArt)
        self.musicImage = self.musicImage.resize((300,300), Image.ANTIALIAS)
        self.realMusicImage = ImageTk.PhotoImage(self.musicImage)
        self.musicCanvas.itemconfigure(self.AlbumArtId, image=self.realMusicImage)
        root.after(1000, self.Update)

我希望它在播放时播放为真,如果暂停则为假,但它始终返回真

【问题讨论】:

    标签: python applescript


    【解决方案1】:

    我解决了这个问题,而是让 applescirpt 返回 1 表示真,0 表示假,然后使用 python 将其转换为 int

    【讨论】:

      猜你喜欢
      • 2020-04-18
      • 1970-01-01
      • 2014-07-11
      • 1970-01-01
      • 1970-01-01
      • 2011-12-02
      • 2011-01-08
      • 2016-11-12
      • 2015-06-12
      相关资源
      最近更新 更多