Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

AppleScript "do script" with a file

New Here ,
Sep 15, 2024 Sep 15, 2024

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

TOPICS
Acrobat SDK and JavaScript , Mac
256
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 15, 2024 Sep 15, 2024

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

 

 

 

 
問題解決に役に立つと良いのですが
参考にしてください

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 16, 2024 Sep 16, 2024
LATEST

Yes, it executes with a string but the dictionary states that it can execute a file and that is what I'm asking.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines