如何登录对象与AppleScript的控制台 [英] How to log objects to a console with AppleScript

查看:515
本文介绍了如何登录对象与AppleScript的控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想记录我整个的AppleScript的生活对象的状态。在其他语言中,对象的toString()方法将呈现文本相当于,我可以使用这些。在AppleScript的,这似乎并不如此。

I am just trying to log the state of objects throughout the life of my applescript. In other languages, object's toString() methods will render the text equivalent and I can use those. In AppleScript, this does not seem to be the case.

convert applescript object to string (similar to toString)

将输出取景器对象(及其属性)的结果的AppleScript编辑器窗口,但只有当它是被执行的最后一条语句。

Will output the finder object (and its properties) to the "Results" window of AppleScript Editor, but only if it is the last statement which gets executed.

如果我有一个trace()语句(这需要一个消息进行日志记录):

If I have a trace() statement (which takes a message for logging purposes):

on trace(message)
do shell script "cat >>~/log/applescript.txt <<END_OF_THE_LOG
" & (message as text) & "
END_OF_THE_LOG"
end trace

和尝试登录同一个对象,我得到

and try to log the same object, I get

Can’t make properties of application "Finder" into type text.

我打开日志记录到一个控制台更好的办法,而是想了解如何写一个对象的属性(如AppleScript的编辑器一样)在脚本中间测试两种方式。

I'm open to better ways of logging to a console, but would like to find out how to write an object's properties (like AppleScript Editor does) in the middle of a script for testing either way.

推荐答案

只需使用AppleScript的在编辑器中的登录语句。当您查看的AppleScript编辑器中的效果,在窗口$ P $底部PSS的事件按钮。通常情况下,结果按钮pressed,然后你只看到最后一条语句的结果你提到。所以更改按钮事件。这将显示您所发生的一切作为脚本运行,另外所有的日志你把整个code太语句。请注意,日志语句不必是文本。您可以登录任何对象。

Just use the log statement in AppleScript Editor. When you view the results in Applescript Editor, at the bottom of the window press the "Events" button. Normally the "Results" button is pressed and then you only see the result of the last statement as you mention. So change the button to "Events". This will show you everything that is happening as the script runs, and additionally all of the log statements that you put throughout the code too. Note that the log statements do not have to be text. You can log any object.

这是调试脚本,看看发生了什么事情的最好方法。作为一个例子尝试这一点,看看事件。实事求是地以为你并不需要大量的登录语句如果查看事件,因为一切都已经登录!

This is the best way to debug your script and see what is happening. As an example try this and look at the "Events". Realistically thought you don't need a lot of log statements if you view the Events because everything is already logged!

set someFolder to path to desktop
log someFolder

tell application "Finder"
    set someItem to first item of someFolder
    log someItem

    set itemProps to properties of someItem
    log itemProps
end tell

这篇关于如何登录对象与AppleScript的控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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