我用 AppleScript 制作了一个名为 FRIDAY 的应用程序。当我告诉它“打开 chrome”时,它会打开谷歌浏览器,这是在脚本编辑器和脚本编辑器的外部工作。我还可以告诉它“打开一个新标签”并使用按键打开一个新标签:
-- this boolean is the reason this script keeps runing
set condition to false
say "Welcome sir"
set commands to {"what is todays date", "what time is it", "what is the time", "what day is it", "what month is it", "which month is it", "friday you up", "friday", "friday you tere", "you there", "empty the trash", "take out the trash", "clean up", "new tab", "next tab", "back", "take a nap", "go to sleep", "take …Run Code Online (Sandbox Code Playgroud) applescript keystroke systemevent applescript-objc system-error
我很好奇AppleScript是否可以访问浏览器中的每个特定选项卡并在其中执行一些javascript.
有人有想法吗?
javascript safari applescript google-chrome applescript-objc
我有一系列AppleScript命令需要在AppleScript的单行中实现.代码如下.
delay 2
tell application "System Events" to keystroke "foo"
tell application "System Events" to keystroke return
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个快速控制iTunes的应用程序.但是在初始化应用程序时返回一个类型的对象AnyObject,但必须是iTunesApplication.
此对象不响应iTunes的方法和变量.谁知道如何使它工作?
var iTunes = SBApplication.applicationWithBundleIdentifier("com.apple.iTunes")
Run Code Online (Sandbox Code Playgroud)
iTunes.h标题还包含我需要访问但不能访问的类.这些类会导致编译错误,就好像它们不在声明的iTunes.h中一样.
为什么这件事发生在我身上尚不清楚.
通过@class声明为iTunes.h的类的完整列表:
@class iTunesPrintSettings,iTunesApplication,iTunesItem,iTunesAirPlayDevice,iTunesArtwork,iTunesEncoder,iTunesEQPreset,iTunesPlaylist,iTunesAudioCDPlaylist,iTunesLibraryPlaylist,iTunesRadioTunerPlaylist,iTunesSource,iTunesTrack,iTunesAudioCDTrack,iTunesFileTrack,iTunesSharedTrack,iTunesURLTrack,iTunesUserPlaylist,iTunesFolderPlaylist,iTunesVisual,iTunesWindow,iTunesBrowserWindow,iTunesEQWindow,iTunesPlaylistWindow;
例如,在Objective -c中,您可以使用类似的东西来获取当前曲目
iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
NSLog(@"Current song is %@", [[iTunes currentTrack] name]);
Run Code Online (Sandbox Code Playgroud)
但我无法迅速获得相同的工作.
我在Xcode的Interface Builder中,创建了一个Cocoa-Applescript自定义Automator Action.我在界面中有一个Button和一个ComboBox菜单.我想在用户单击Button时填充ComboBox菜单的内容值.我创造了
on buttonSentAction_(sender)
-- set popupMenuContentValues of my parameters() to aList as list
my popupMenu's addItemsWithObjectValues_(aList)
end buttonSentAction_
Run Code Online (Sandbox Code Playgroud)
在applescript文件中的处理程序,但当我从按钮拖动到文件的所有者时,文件的所有者不会突出显示我放弃连接.我期待的是它放弃并让我选择buttonSentAction_处理程序来接收发送的动作.如果我右键单击File's Owner,我在Applescript控制器文件中创建的收到的操作处理程序不会显示.(注意,我仍然不确定在该处理程序中填充ComboBox菜单的正确行.)

我可以在"FM to Named Text Boxes"中看到示例macosxautomation.com上的Automator Action项目在IB中有一个按钮,您可以在Bindings Inspector中看到按钮的发送动作实际上已连接到文件所有者,并且applescript文件具有匹配的处理程序.另外,我默认将File's Owner的控制器设置为applescript文件.显然,我遗漏了一些关于在Automator Action Project中挂起已发送动作的具体内容.有帮助吗?
目标
每当标题(或当然是活动应用程序)发生变化时,我想在 Swift 中打印到控制台,最前面的活动应用程序的最前面窗口的完整窗口标题。我对 Swift/Objective-C 都很陌生,所以如果也建议 ObjC 中的任何解决方案,我也会非常高兴。(因为有一个叫做AppleScriptObjc的东西,但我只是不明白它是如何工作的)
到目前为止我做了什么
class activeApp: NSObject {
override init() {
super.init()
NSWorkspace.shared.notificationCenter.addObserver(self,
selector: #selector(printMe(notification:)),
name: NSWorkspace.didActivateApplicationNotification,
object:nil)
}
@objc func printMe(notification: NSNotification) {
let app = notification.userInfo!["NSWorkspaceApplicationKey"] as! NSRunningApplication
let myAppleScript = """
tell application "System Events"
return name of first window of (first application process whose frontmost is true)
end tell
"""
let script = NSAppleScript(source: myAppleScript)!;
var errorDict : NSDictionary?
print(script.executeAndReturnError(&errorDict).stringValue as Any)
print(app.localizedName!)
}
}
let runme = activeApp()
RunLoop.main.run()}
Run Code Online (Sandbox Code Playgroud)
我知道此代码仅在活动应用程序更改时打印窗口标题和活动应用程序,而不是在同一应用程序中标题更改时打印。但是,我想在处理控制台上显示的错误后处理该问题。 …
我似乎无法弄清楚如何识别给定应用程序可用的权利密钥.如何查询应用程序的权利密钥?
示例:iTunes具有以下授权键:com.apple.iTunes.playerInfo,com.apple.iTunes.library.read-write,&com.apple.iTunes.playback
但如果我还不知道这一点,我怎么能从iTunes应用程序中检索这些键呢?那么第三方(非Apple)应用程序呢?如果有的话,哪里可以找到权利密钥?
提前致谢!
entitlements scripting-bridge applescript-objc appstore-sandbox
当我使用AppleScript获取对象的属性时,将返回一条记录.
tell application "iPhoto"
properties of album 1
end tell
==> {id:6.442450942E+9, url:"", name:"Events", class:album, type:smart album, parent:missing value, children:{}}
Run Code Online (Sandbox Code Playgroud)
如何迭代返回记录的键/值对,以便我不必确切地知道记录中的键是什么?
为了澄清这个问题,我需要枚举键和值,因为我想编写一个通用的AppleScript例程来将记录和列表转换为JSON,然后由脚本输出.
我的Applescript在Safari中遇到了这个错误(偶尔).
Result:
error "Safari got an error: Can’t get document \"DOC TITLE\"."
number -1728 from document "DOC TITLE"
Run Code Online (Sandbox Code Playgroud)
我认为这是因为页面没有加载,但我有一个Javascript在继续之前检查"完成",以及一个try语句延迟错误的另一秒.
不过,我仍然遇到这个问题.它似乎相当随机.
有什么建议?
Applescript(整个Tell声明):
tell application "Safari"
set the URL of the front document to searchURL
delay 1
repeat
if (do JavaScript "document.readyState" in document 1) is "complete" then exit repeat
delay 1.5 -- wait a second before checking again
end repeat
try
set doc to document "DOC TITLE"
on error
delay 1
set doc to document "DOC TITLE"
end try
set …Run Code Online (Sandbox Code Playgroud) javascript safari applescript applescript-excel applescript-objc
我试图在OS X Yosemite中创建一个菜单栏应用程序,它只包含一个带子菜单的下拉菜单.此菜单及其子菜单将由applescript脚本填充.
我之前已经找到了类似的教程,但它们似乎都已经过时了,并且在Xcode 6.2中没有正常工作,例如:
我在Applescript方面经验丰富,但没有太多时间在Objective C中编写代码.
哪里可以找到我想要创建的各种模板的好地方?
applescript-objc ×10
applescript ×8
javascript ×2
macos ×2
objective-c ×2
safari ×2
swift ×2
xcode ×2
automator ×1
cocoa ×1
entitlements ×1
itunes ×1
json ×1
keystroke ×1
line ×1
menubar ×1
system-error ×1
systemevent ×1