本文介绍了Applescript 通过属性的字符串名称获取属性的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 AppleScript 中.假设我有一个名为 Title 的属性的记录.
In AppleScript. Let's say I have a record with a property called Title.
假设我为文本标题"设置了一个变量;我可以使用该变量来获取属性 Title 的值吗?基本上,有没有办法做这样的事情:
Let's say I set a variable to the text "Title"; can I use that variable to get the value of the property Title? Basically, is there any way to do something like this:
set result to property named "Title" of myRecord
代替:
set result to Title of myRecord
推荐答案
我找到了答案.我也意识到我没有问正确的问题.我试图获取的值来自属性列表项.
I found the answer. I also realize I didn't ask the correct question. The value I'm trying to obtain is from a property list item.
这是我学到的东西,以及如何做到这一点:
Here's what I learned, and how to accomplish this:
use framework "Foundation"
set _plist to ...
set _objcPlist to GetAppleScriptObjectAsObjcObject(_plist)
set _value to GetObjcPropertyValueByName("MyProperty", item 1 of _objcPlist)
on GetAppleScriptObjectAsObjcObject(asObject)
set a to current application
set cClass to class of asObject
if (cClass is record) then
return a's NSDictionary's dictionaryWithDictionary:asObject
else if (cClass is list) then
return a's NSArray's arrayWithArray:asObject
else
error "Unexpected Class Type"
end if
end GetAppleScriptObjectAsObjcObject
on GetObjcPropertyValueByName(propertyName, objcItem)
return (objcItem's valueForKey:propertyName) as text
end GetObjcPropertyValueByName
这篇关于Applescript 通过属性的字符串名称获取属性的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!