有什么办法可以将下面的苹果脚本转换为Objective-C/C吗?从Objective-C/C发送系统事件的请求?
tell application "System Events" to set visible of process "Safari" to false
我知道我可以使用NSAppleScript
类或调用system("osascript -e '...'")
在Objective-C执行该AppleScript的,但是是不是有另一种方式?
苹果如何做到这一点?
或者,我可以从Objective-C/C的另一个应用程序隐藏窗口吗?
更新:
我发现,您可以使用SBApplication
类来做到这一点:
SBApplication *SystemEvents = [SBApplication applicationWithBundleIdentifier:@"com.apple.systemevents"];
/*SystemEventsApplicationProcess*/ id Safari = [[SystemEvents performSelector:@selector(applicationProcesses)] objectWithName:@"Safari"];
[Safari setVisible:NO]; // Doesn't work!
但是这不工作为setVisible
可能没有做什么,我想。
这是SystemEventsApplicationProcess
的类层次结构:
SystemEventsApplicationProcess : SystemEventsProcess : SystemEventsUIElement : SystemEventsItem : SBObject : NSObject
这里是这些SystemEventsXXX
类可用的方法:
SystemEventsApplicationProcess
applicationFile
SystemEventsProcess
setVisible:
visible
unixId
totalPartitionSize
shortName
partitionSpaceUsed
name
id
hasScriptingTerminology
setFrontmost:
frontmost
fileType
file
displayedName
creatorType
Classic
bundleIdentifier
backgroundOnly
architecture
acceptsRemoteEvents
acceptsHighLevelEvents
windows
menuBars
SystemEventsUIElement
select
clickAt:
setValue:
value
title
subrole
setSize:
size
setSelected:
selected
roleDescription
role
setPosition:
position
orientation
name
minimumValue
maximumValue
help
setFocused:
focused
entireContents
enabled
objectDescription
objectClass
accessibilityDescription
windows
valueIndicators
UIElements
toolBars
textFields
textAreas
tables
tabGroups
staticTexts
splitterGroups
splitters
sliders
sheets
scrollBars
scrollAreas
rows
relevanceIndicators
radioGroups
radioButtons
progressIndicators
popUpButtons
popOvers
outlines
menuItems
menuButtons
menuBarItems
menuBars
menus
lists
incrementors
images
growAreas
groups
drawers
comboBoxes
columns
colorWells
checkboxes
buttons
busyIndicators
browsers
attributes
actions
SystemEventsItem
setName:
name
id
removeActionFromUsingActionName:usingActionNumber:
pick
keyUp
keyDown
increment
editActionOfUsingActionName:usingActionNumber:
doScript
doFolderActionFolderActionCode:withItemList:withWindowSize:
decrement
confirm
cancel
attachedScripts
attachActionToUsing:
stop
start
saveAs:in:
moveTo:
exists
duplicateTo:withProperties:
delete
closeSaving:savingIn:
setProperties:
properties
objectClass
SBObject
// ...
NSObject
// ...
曾经有一个碳功能,'AESend()',对于这一点,但它在碳的过时的部分。有传言说,碳位仍然为可可的AppleEvents系统的基础,但考虑到即使文档“苹果事件编程指南”和“苹果事件管理指南”已经消失,似乎'NSAppleScript'或'SBApplication'是前进的道路。 – 2012-08-04 19:46:54