AppleScript "do script" with a file
Copy link to clipboard
Copied
I'm trying to execute a javascript file in Acrobat.
tell application "Adobe Acrobat"
do script file theFilepath as alias
end tell
But Acrobat (24.002.21005) crashes. The contents of the file "theFilepath" executes if do script is called using a string.
What am I doing wrong?
Thanks!
Doug
Copy link to clipboard
Copied
I'm not very good at English, so please excuse me for writing in Japanese.
Doug26さん
日本語でのアドバイスになってしまいます。申し訳ない。
ファイルになっているjavascriptをAcrobatで実行する方法は
色々な方法があるけど
あくまでもひとつの方法として
ファイル=JSfileを読み込んで実行すれば良いんじゃないかな?と思います
#!/usr/bin/env osascript
set strWriteJs to ("console.show();\nconsole.clear();\nconsole.println(\"\");") as text
set aliasDesktopDirPath to (path to desktop folder from user domain) as alias
set strDesktopDirPath to (POSIX path of aliasDesktopDirPath) as text
set strJsFilePath to (strDesktopDirPath & "open_console.js") as text
set aliasJsFilePath to (POSIX file strJsFilePath) as «class furl»
tell application "Finder"
make new file at aliasDesktopDirPath with properties {name:"open_console.js"}
end tell
#WriteFile
write strWriteJs to aliasJsFilePath starting at eof
#or
#write strWriteJs to strJsFilePath starting at eof
#ReadFile
set strReadJS to read aliasJsFilePath
#or
#set strReadJS to read strJsFilePath
tell application "Adobe Acrobat Reader"
activate
do script strReadJS
end tell
簡素化して書くと
set aliasJsFilePath to (POSIX file "/some/dir/some/file.jsx") as alias
tell application "Adobe Acrobat Reader"
activate
do script (read file aliasJsFilePath as string)
end tell
ネットワーク上のJavascriptも参照できます
#!/usr/bin/env osascript
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
#FILEURL
set strFileURL to ("https://gist.githubusercontent.com/force4u/5c872f5e34bf636e1c89dd0cfd9adacb/raw/52256b68877baa655dfcf71946028636c4ef2c90/open_console.js") as text
set ocidURLString to current application's NSString's stringWithString:(strFileURL)
set ocidURL to current application's NSURL's alloc()'s initWithString:(ocidURLString)
#ReadFile
set listReadStrings to current application's NSString's alloc()'s initWithContentsOfURL:(ocidURL) encoding:(current application's NSUTF8StringEncoding) |error|:(reference)
set strReadJS to (item 1 of listReadStrings) as text
tell application "Adobe Acrobat Reader"
activate
do script strReadJS
end tell
問題解決に役に立つと良いのですが
参考にしてください
Copy link to clipboard
Copied
Yes, it executes with a string but the dictionary states that it can execute a file and that is what I'm asking.

