我刚刚开始玩Geektool和applescripting让我的Mac桌面变得有趣,我遇到了一个似乎无法找到答案的问题.你如何从osascript命令获得当前的歌曲播放时间?我已经找到了很多资源,如何在命令行上使用iTunes和osascript做任何其他事情,但似乎没有人关心显示当前的播放时间.谢谢!我假设它将是这样的:
osascript -e 'tell application "iTunes" to time of current track'
Run Code Online (Sandbox Code Playgroud)
我已经试过了,它告诉我这首歌有多长.我想知道它玩了多久.
我有一个正在我的计算机上运行的Applescript,但不在我的同事身上.操作路径时出现两个错误:-10004和-10000.我知道如何解决这个问题,但首先我想了解这些错误代码.
这是脚本(我删除了无用的部分,完整版本在github上):
-- export all layers to image files
-- Settings
property exportFileExtension : "png"
property ADD_CANVAS_NUMBER : true
-- End of Settings
on file_exists(FileOrFolderToCheckString)
try
alias FileOrFolderToCheckString
return true
on error
return false
end try
end file_exists
tell application "OmniGraffle Professional 5"
set theWindow to front window
set theDocument to document of theWindow
set theFilename to name of theDocument
-- remove .graffle
-- FIRST ERROR IS HERE -10004
set theFilename to …Run Code Online (Sandbox Code Playgroud) 我想列出终端中打开的窗口,以获得xwininfo -root -treeX11的x,y,宽度和高度.
我试过了:
osacript -e tell application "Microsoft Word" to get the bounds of the front window
Run Code Online (Sandbox Code Playgroud)
但它并不适用于所有应用程序而您无法指定子项(如果您有两个Word文档,则返回第一个打开的文档).
我有一个bash脚本,我生成一些数字将它们分配给变量然后使用osascript在任何选择的应用程序中写出它们.
这是我想要做的简化版本.
monday1=5
osascript -e 'tell application "System Events" to keystroke "$monday1"'; \
Run Code Online (Sandbox Code Playgroud)
osascript应该是这样的
osascript -e 'tell application "System Events" to keystroke "5"'; \
Run Code Online (Sandbox Code Playgroud)
然后,这将在我的光标应用程序中键入数字5.问题是它输出$ monday1而不是.我知道我必须做一些事情来逃避引号,所以脚本可以输入变量,但我不知道如何.
思考?
终端中的Osascript始终为最简单的函数返回此错误.
当我在ApplescriptEditor中运行脚本时运行良好...
例如:
$: osascript -e 'tell application "iTerm" to display dialog "Hello World"'
2014-01-22 11:59:19.822 osascript[665:707] Cannot find executable for CFBundle 0x7fa3f42032e0 </Library/ScriptingAdditions/AeroFSFinderExtension.osax> (not loaded)
osascript: OpenScripting.framework - scripting addition
"/Library/ScriptingAdditions/AeroFSFinderExtension.osax" declares no loadable handlers.
button returned:OK
Run Code Online (Sandbox Code Playgroud)
我已经重新安装了XCode和CLL(使用Appcleaner)
有谁知道如何解决这个错误?(或至少让它沉默......)
我在10.8.5
尝试' '在我的 osascript 命令中包含引号时遇到了一个奇怪的问题。
如果我尝试转义一个正常的可转义字符,它工作正常。示例:osascript -e 'tell app "Finder" to display dialog "Te\\st"'来自 Finder 的对话框弹出,其中包含文本Test。
但是,当我在写出完整句子时尝试使用撇号时,就会出现问题。示例:osascript -e 'tell app "Finder" to display dialog "Te\'st"'当我运行它时,只剩下没有对话框,终端中的文本输入如下所示:
>
据我所知,这无论如何都应该起作用,但是,它没有。
我想弄清楚JXA(JavaScript for Automation)是如何工作的,所以尝试将如下的简单AppleScript翻译成JXA.
tell application "Finder"
open location "smb://XXXXXXXX"
end tell
Run Code Online (Sandbox Code Playgroud)
我试过的是这里:
finder = Application("Finder")
finder.open({location:"smb://xxxxxx"})
Run Code Online (Sandbox Code Playgroud)
但是我失败了...,我是Apple的新手,并不是真正理解库中的描述.这是图书馆描述的方式open
open?(v) : Open the specified object(s)
open specifier : list of objects to open
[using specifier] : the application file to open the object with
[with properties record] : the initial values for the properties, to be included with the open command sent to the application that opens the direct object
Run Code Online (Sandbox Code Playgroud)
请告知我应该如何修改代码.^^谢谢
我是终端脚本新手,我正在尝试转换
osascript -e 'tell app "Terminal"
do script "ssh -t jgreen@dev-jgreen-bs pwd"
end tell'
Run Code Online (Sandbox Code Playgroud)
这适用于多行,但我想要一个单行脚本,但我不能完全正确。我不断收到 2741 错误,我知道这是我失败的语法。
我尝试过 /, ,, \n, -e, &,to作为分隔符。
我有一些苹果脚本代码:
tell application "System Events"
key code 97
end tell
Run Code Online (Sandbox Code Playgroud)
如何osascript -e在终端中将代码编写为命令?每次我尝试使用\n或等等,我都会收到错误.对不起,如果我不够具体.
有一个 AppleScript 方法:
on displayError(theErrorMessage)
display dialog theErrorMessage
return "done"
end displayError
Run Code Online (Sandbox Code Playgroud)
我想通过传递参数来编译这个脚本(不要用 osascript 运行它!)My_Application.app
就像是
osacompile - o My_Application.app My_Script.applescript "This is error message as parameter"
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我将编译可以运行的应用程序。寻找有关如何使用传递参数准确编译脚本的命令。由于编译需要很多时间 - 我只想做一个。运行My_Application.app后,比通过 osascript运行的速度要快很多倍。如果输入参数改变 - 只需重新编译应用程序。
一个不错的选择是从运行的应用程序中以某种方式收集返回值,但这是另一个问题
osascript ×10
applescript ×7
terminal ×3
bash ×2
macos ×2
command-line ×1
error-code ×1
escaping ×1
itunes ×1
javascript ×1
path ×1
shell ×1