无法使用AppleScript运行javascript函数

时间:2016-04-16 21:42:30

标签: javascript applescript

我正在尝试使用applescript控制网站的视频功能。该网站有一个flash视频 - jwplayer。在谷歌浏览器中,如果我输入命令

,我就可以暂停视频

class LayoutManager : NSLayoutManager { var text: String? { return textStorage?.string } var font: UIFont = UIFont.systemFontOfSize(UIFont.systemFontSize()) { didSet { guard let text = self.text else { return } let textRange = NSMakeRange(0, (text as NSString).length) invalidateGlyphsForCharactersInRange(textRange, actualCharacterRange: nil) invalidateCharacterAttributesForCharactersInRange(textRange, actualCharacterRange: nil) } } override func drawBackgroundForGlyphRange(glyphsToShow: NSRange, atPoint origin: CGPoint) { super.drawBackgroundForGlyphRange(glyphsToShow, atPoint:origin) guard let text = self.text else { return } enumerateLineFragmentsForGlyphRange(glyphsToShow) { (rect: CGRect, usedRect: CGRect, textContainer: NSTextContainer, glyphRange: NSRange, stop: UnsafeMutablePointer<ObjCBool>) -> Void in let characterRange = self.characterRangeForGlyphRange(glyphRange, actualGlyphRange: nil) // Draw invisible tab space characters let line = (self.text as NSString).substringWithRange(characterRange) do { let expr = try NSRegularExpression(pattern: "\t", options: []) expr.enumerateMatchesInString(line, options: [.ReportProgress], range: line.range) { (result: NSTextCheckingResult?, flags: NSMatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) in if let result = result { let range = NSMakeRange(result.range.location + characterRange.location, result.range.length) let characterRect = self.boundingRectForGlyphRange(range, inTextContainer: textContainer) let symbol = "\u{21E5}" let attrs = [NSFontAttributeName : Font] let height = (symbol as NSString).sizeWithAttributes(attrs).height symbol.drawInRect(CGRectOffset(characterRect, 1.0, height * 0.5, withAttributes: attrs) } } } catch let error as NSError { print(error.localizedDescription) } } } }

但是,如果我通过AppleScript发送命令,则无法正常工作。

enter image description here

我得到的控制台错误消息如下

enter image description here

点击VM4054:2给我这个

enter image description here

1 个答案:

答案 0 :(得分:0)

使用Safari是一种选择吗?这有效......

tell application "Safari"
    repeat with t in tabs of windows
        tell t
            if URL starts with "https://www.jwp" then
                do JavaScript "jwplayer().pause();"
            end if
        end tell
    end repeat
end tell