通过这个简单的AppleScript,我可以列出iTunes中所有歌曲的名称
tell application "iTunes"
set mainLibrary to library playlist 1
repeat with nexttrack in (get every track of mainLibrary)
try
name of nexttrack
end try
end repeat
end tell
Run Code Online (Sandbox Code Playgroud)
然后我使用ScriptEngine将其作为Java 7代码运行,但是很明显如何获取脚本的结果,在这种情况下只是最后一个轨道的名称.
StringBuilder script =new StringBuilder();
script.append("tell application \"iTunes\"\n");
script.append("set mainLibrary to library playlist 1\n");
script.append("repeat with nexttrack in (get every track of mainLibrary)\n");
script.append("try\n");
script.append("name of nexttrack\n");
script.append("end try\n");
script.append("end repeat\n");
script.append("end tell\n");
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("AppleScript");
System.out.println(engine.eval(script.toString()));
How do can I capture the name …Run Code Online (Sandbox Code Playgroud) 我需要一个使用applescript创建的记录列表.我正在尝试在Applescript中创建一个像Hash Table这样的Java.
set grocery_list to {"milk", "butter", "eggs"}
set milk to {name:"Whole Milk", quantity:"1 Gallon", brand:"Newland Farms" }
set butter to {name:"Unsalted Butter", quantity:"1 pound", brand:"Land O Lakes"}
set eggs to {name:"Grade A jumbo eggs", quantity:"1 dozen", brand:"Farm Fresh"}
Run Code Online (Sandbox Code Playgroud)
我需要一种方法来创建这种结构,我可以访问以下内容:
遍历列表,获取单个项目,每个项目获得品牌.
我试过这个
say brand of (item 1 of grocery_list)
Run Code Online (Sandbox Code Playgroud)
但这给了我一个错误
Can’t get brand of \"milk\"." number -1728 from brand of "milk"
Run Code Online (Sandbox Code Playgroud)
有没有推荐的方法来实现这个?
提前致谢
我正在使用mac osx 10.8.5在python中创建一个应用程序我通过使用将python脚本转换为应用程序py2app.但是,在app中,On Show Package Contents-->Contents-->Resources原始代码存在.我不希望通过分发我的应用程序作为安全问题来向其他人显示我的代码.我用(.pyc)代码删除了(.py)代码,在这种情况下,应用程序无法正常工作.请为它提供一些方法.我也搜索其他问题,但没有得到预期的结果.我的setup.py是
from setuptools import setup
APP=['myapp.py']
DATA_FILES= [('',['config.cfg'])]
OPTIONS={'iconfile':'cc.icns','argv_emulation': True,'plist':{'CFBundleShortVersionString':'1.0'}}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app']
)
Run Code Online (Sandbox Code Playgroud) 我对脚本的一个简单部分有疑问,我想在其中获取属性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) applescript ×10
macos ×6
swift ×2
arguments ×1
click ×1
contain ×1
events ×1
hashtable ×1
if-statement ×1
java ×1
mouse ×1
objective-c ×1
osascript ×1
powerpoint ×1
py2app ×1
python ×1
scriptengine ×1
scripting ×1
shell ×1
system ×1
vba ×1