更快速地检查应用程序是否在AppleScript中运行

时间:2016-05-12 04:56:26

标签: applescript

我在一个应该响应的程序中使用AppleScript,但似乎我在检查应用程序是否正在运行时遇到瓶颈,这需要大约半秒......有没有办法减少这个?

这是我目前正在做的事情:

extension UIImage {
    func imageByCroppingImage(size: CGSize) -> UIImage {
        let newCropWidth, newCropHeight : CGFloat;

        if(self.size.width < self.size.height) {
            if (self.size.width < size.width) {
                newCropWidth = self.size.width;
            }
            else {
                newCropWidth = size.width;
            }
            newCropHeight = (newCropWidth * size.height)/size.width;
        } else {
            if (self.size.height < size.height) {
                newCropHeight = self.size.height;
            }
            else {
                newCropHeight = size.height;
            }
            newCropWidth = (newCropHeight * size.width)/size.height;
        }

        let x = self.size.width / 2 - newCropWidth / 2;
        let y = self.size.height / 2 - newCropHeight / 2;

        let cropRect = CGRectMake(x, y, newCropWidth, newCropHeight);
        let imageRef = CGImageCreateWithImageInRect(self.CGImage, cropRect);

        let croppedImage : UIImage = UIImage(CGImage: imageRef!, scale: 0, orientation: self.imageOrientation);

        return croppedImage;
    }
}

1 个答案:

答案 0 :(得分:4)

这就是我正在使用的(在这种情况下是Word),它似乎足够快(少于0.5秒)。结果是Appli_Launch = true或false:

tell application "System Events" to set Appli_Launch to exists (processes where name is "Microsoft Word")