我对脚本的一个简单部分有疑问,我想在其中获取属性dock preferences系统事件的属性。我有以下内容:
tell application "System Events"\n tell appearance preferences\n set ap_prefs to (get the properties)\n set ap_prefs to the properties\n end tell\n set a_pref to the properties of appearance preferences\n\n -- Error Part\n tell dock preferences\n set d_prefs to (get the properties)\n end tell\n set d_pref to the properties of dock preferences\nend tell\nRun Code Online (Sandbox Code Playgroud)\n\n在上面的代码中,我appearance preferences以上面显示的所有方式访问,但不是dock preferences. 它给出一个错误error "System Events got an error: AppleEvent handler failed." number -10000。
那么到底发生了什么事,为什么只在码头上出现错误?这里 …
我希望能够从屏幕上最前面的窗口获取所有文本,将其通过管道传输到 url 解析器,并从解析的文本中选择要打开的 url。
为此,我需要一种方法来访问最前面窗口的所有文本内容。我已经通过使用 applescript 接近了,但我找不到获取实际文本的方法。我怀疑 swift 可能会有所帮助,但我不知道如何用谷歌搜索这个,因为我的大多数搜索最终都只找到了一些微不足道的方法,例如从 chrome 中的选项卡获取网址等。
这就是我想要的要点:
tell the frontmost application
get contents of frontmost window as text
end tell
Run Code Online (Sandbox Code Playgroud) 此代码用于单击屏幕上的特定位置,但是如何单击光标的坐标呢?
tell application "System Events"
click at {10, 10}
end tell
Run Code Online (Sandbox Code Playgroud) set r to ""
set device to "IPHONE 6 PLUS SILVER 128GB-AUS"
set HighValueDevicesPass to {"IPHONE 7", "IPHONE 6", "IPAD PRO", "IPHONE 6S", "IPHONE 6 PLUS"}
if devices contains HighValueDevicesPass then
set r to "Pass"
end if
return r
Run Code Online (Sandbox Code Playgroud)
我不明白为什么这不起作用。该变量是“IPHONE 6 PLUS SILVER 128GB-AUS”,因此实际上包含列表中的“IPHONE 6 PLUS”。
如果我使用 IF is on the list,它工作正常,但随后我必须将所有不同的模型设置为变量。
如何进行部分匹配?
目标
每当标题(或当然是活动应用程序)发生变化时,我想在 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)
我知道此代码仅在活动应用程序更改时打印窗口标题和活动应用程序,而不是在同一应用程序中标题更改时打印。但是,我想在处理控制台上显示的错误后处理该问题。 …
我有以下使用osascript命令的 shell 脚本:
#!/usr/bin/osascript
on run argv
tell application "Terminal"
activate
do script "echo " & quoted form of (item 1 of argv) & " " & quoted form of (item 2 of argv)
end tell
end run
Run Code Online (Sandbox Code Playgroud)
但是,当我运行时,代码仅限于打印 2 个第一个参数。
例如,运行时./test.sh foo bar buzz ...,我希望显示所有参数。
如何将上述代码转换为支持多个无限数量的参数?当我不指定任何内容时它不会中断?
如何使用 VBA 或 Apple 脚本从演示文稿中拆分幻灯片。以前我使用 VBA 代码来实现相同的目的,但在 powerpoint 16.13.1 中我收到错误“Mac PPT 不支持在无窗口模式下打开文件”。它适用于以前版本的 PowerPoint。
Sub SaveSlide(lSlideNum As Long, sFileName As String)
Dim oTempPres As Presentation
Dim x As Long
ActivePresentation.SaveCopyAs sFileName
' open the saved copy windowlessly
Set oTempPres = Presentations.Open(sFileName, , , False)
For x = 1 To lSlideNum - 1
oTempPres.Slides(1).Delete
Next
' What was slide number lSlideNum is now slide 1
For x = oTempPres.Slides.Count To 2 Step -1
oTempPres.Slides(x).Delete
Next
oTempPres.Save
oTempPres.Close
End Sub
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我在这一行中遇到错误
Set oTempPres …Run Code Online (Sandbox Code Playgroud) 我想在内存非常低的设备中测试我的项目移动应用程序安装。假设大约 1 GB。它xcode带有定义的 RAM 大小。
有什么方法可以xcode像在 Android studio 中那样自定义 RAM 大小。
如果是,怎么办?
如果没有,是否有其他替代方案或模拟器类型可以用于此测试?
我希望能够随时知道用户当前在 macOS 10.13 上以编程方式使用哪个任务控制工作区。在搜索过程中我找不到任何有效的答案。任何语言都可以,任何工作区标识符都适合我(uuid、工作区编号...)
感谢您的帮助!
我想知道是否可以修改右键单击 Finder 中任何特定内容时弹出的上下文菜单(如下右侧所示)
我可以轻松地将选项添加到右键单击某个项目(左侧)时弹出的上下文菜单...但是有没有办法将选项添加到右侧的菜单中?
例如,我可以在“新文件夹”下方添加自定义选项“新 Majig”吗?
更多信息:
如果它有用,以下是我创建我想要使用的选项的方法:
细节:
我在莫哈韦 10.14.2
applescript ×10
macos ×7
swift ×2
appium-ios ×1
arguments ×1
automator ×1
click ×1
cocoa ×1
contain ×1
contextmenu ×1
events ×1
if-statement ×1
ios ×1
macos-mojave ×1
mouse ×1
objective-c ×1
osascript ×1
performance ×1
powerpoint ×1
shell ×1
system ×1
vba ×1
xcode ×1