设置卷不工作在xcode与applescript可可objc [英] set volume not working in xcode with applescript cocoa objc

查看:263
本文介绍了设置卷不工作在xcode与applescript可可objc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在xcode 3.2中有一个applescript xcode项目,我试图更改系统卷...但它不工作...它停止nstimer或不做任何东西...



这是我的代码

有没有办法记录错误,

 将newVolume设置为50 
设置卷输出音量newVolume
textName的setStringValue_(currentVolume)
将currentVolume设置为newVolume

obv这是一个更加精简的版本,但这在字面上不工作...它是在一个NSTimer,但即使不在NSTimer内,它仍然不工作... newVolume,currentVolume和textName都声明...我需要声明一些设置卷行吗?

解决方案

所以,你的实际问题只是如何记录来自AppleScriptObjC的错误:



AppleScriptObjC会记录任何你的脚本中抛出的错误到控制台 - 只需在Xcode的底部窗格。例如,在你的情况下,你应该看到像«脚本»不明白aevtstvl»消息。(这不是很清楚,但它告诉你,你的脚本发送一个集volume 命令到一个脚本对象,它没有一个处理程序)。如果你想捕获和记录错误自己,你可以把麻烦的部分放在 try / 在错误块上,并在错误处理程序中自己处理。



你也会感到额外的好奇,你也可以打开 NSScriptingDebugLogLevel 偏好,如下:

  defaults write com.me.myapp NSScriptingDebugLogLevel 1 

...和AppleScriptObjC记录关于在桥上发送的每条消息的信息。 (将其设置为0或使用 defaults delete 将其关闭。)



这是错误记录。现在,你实际上没有问,但我要回答,我如何解决我的设置卷命令?



简短版本:添加将当前应用程序告知

 code>告诉当前应用程序设置卷输出量50 

新卷参数为0到100.旧兼容性从0到7.(为什么?旧的控制面板音量滑块有8个停止。)



长版本:



默认直接参数和设置卷的处理之间存在不良交互。当使用AppleScriptObjC时,it,因此默认的直接参数,除非另有说明,是当前脚本,并且设置卷阻塞。你可以通过将当前应用程序告诉来强制it为空。 (或者,您可以使用旧版形式设置卷x 为其提供显式直接参数,其中 x 从0到7的实数。但是,这不匹配从获取卷设置中获得的数字,只允许您设置输出音量,不允许你可以正确设置静音)。



顺便说一下,如果你的AppleScriptObjC项目足够简单(特别是如果你不需要任何接口) ,您可以直接在AppleScript编辑器中写入:选择文件>从模板新建> Cocoa-AppleScript Applet,并使用正常的AppleScript 运行打开处理程序,除了现在您还可以调用Cocoa中的任何内容。


I have an applescript xcode project in xcode 3.2 and am trying to change the system volume...however it doesn't work...it either stops the nstimer or doesnt do anything at all...

Is there a way to log the errors so that I can pinpoint the issue?

Here is my code

set newVolume to 50
set volume output volume newVolume
textName's setStringValue_(currentVolume)
set currentVolume to newVolume

obv this is a much more condense version but this literally does not work...it is inside of an NSTimer but, even when not within an NSTimer it still does not work...newVolume, currentVolume, and textName are all declared...do I need to declare something for the set volume line?

解决方案

So, your actual question was simply how to log errors from AppleScriptObjC:

AppleScriptObjC will log any errors thrown in your script to the console -- just look in the bottom pane in Xcode. For instance, in your case you should see something like "«script» doesn’t understand the «aevtstvl» message." (This isn’t terribly clear, but it’s telling you that your script sent a set volume command to a script object, which didn’t have a handler for it.) If you want to capture and log errors yourself, you can put troublesome sections inside a try/on error block, and deal with it yourself in the error handler.

If you’re feeling extra inquisitive, you can also turn on the NSScriptingDebugLogLevel preference, like this:

defaults write com.me.myapp NSScriptingDebugLogLevel 1

...and AppleScriptObjC will log information about every message sent either way across the bridge. (Set it to 0 or use defaults delete to turn it off.)

That’s error logging. Now, what you didn’t actually ask, but I’m going to answer anyway, was "How do I fix my set volume command?"

Short version: add tell current application to:

tell current application to set volume output volume 50

And yes, the range for the "new" volume parameters is 0 to 100. The old compatibility one goes from 0 to 7. (Why? The old Control Panel volume slider had 8 stops.)

Long version:

There’s a bad interaction between the default direct parameter and set volume’s handling of it. When using AppleScriptObjC, "it", and therefore the default direct parameter, unless you say otherwise, is the current script, and set volume chokes on that. You can force "it" to be nothing by saying tell current application to. (Alternatively, you could give it an explicit direct parameter by using the old-fashioned form set volume x where x is a real number from 0 to 7. However, this doesn’t match the numbers you get from get volume settings, only lets you set the output volume, and doesn’t let you set things like "muted" correctly.)

And by the way, if your AppleScriptObjC project is sufficiently simple (in particular, if you don’t need any interface), you can write it directly in AppleScript Editor: choose File > New from Template > Cocoa-AppleScript Applet, and use the normal AppleScript on run and on open handlers, except that you can now also invoke anything from Cocoa.

这篇关于设置卷不工作在xcode与applescript可可objc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆