私はApplescriptを使用して自動化する非常に特殊なファイルシステムを持っています。私が使用しているスクリプトは大部分は機能しますが、適切に調整することができない小さなステップが1つあります。スクリプトはこのように動作するはずです。スクリプトが実行されると、スクリプトはユーザーにフォルダの選択を要求します。選択されたスクリプトは、特定の拡張子(この場合はjpg)を持つフォルダ内のすべてのファイルを検索します。次に、スクリプトは新しいファイル名として画像ファイル名を使用して、各jpgファイルの空白のテキストドキュメントを作成します。完了すると、新しいテキスト文書は、別の事前に指定されたファイルからテキストを入力する必要があります。新しい空ファイルへの書き込み(AppleScriptを使用)
たとえば、ファイルを実行して3つのイメージ(cake1.jpg、pie2.jpg、icecream3.jpg)を含むフォルダを選択します。スクリプトは3つのテキストドキュメント(cake1.txt、pie2.txt、icecream3.txt)を作成し、作成した新しい文書のそれぞれにScript2Text.rtfからテキストをコピーする必要があります。ここで私が持っているスクリプトの一部は、作品と私は
set aFolder to choose folder "Select folder to be processed"
set extensionText to text of "txt"
set theDocument to ((path to desktop as Unicode text) & "Script2Text.rtf")
set pasteText to (read file theDocument from 1)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "{"
set pasteText to text from text item 2 to -1 of pasteText
set AppleScript's text item delimiters to "\\marg"
set part1 to text item 1 of pasteText
set part2 to text from text item 2 to -1 of pasteText
set AppleScript's text item delimiters to astid
set RTFreturn to "\\" & return
set pasteText to RTFreturn & RTFreturn & part1 & text from paragraph 2 to -1 of part2
tell application "Finder"
set allFiles to every file of entire contents of aFolder whose name extension is in {"jpg"}
repeat with x in allFiles
set FileName to name of x
if FileName contains ".jpg" then
set AppleScript's text item delimiters to "jpg"
if the (count of text items of FileName) is 2 then
set NewName to (((first text item of FileName) as string) & extensionText & ((last text item of FileName) as string)) as text
tell application "Finder" to make file at aFolder with properties {name:NewName}
else
display dialog ("Text appears more than once. No changes made to " & FileName)
end if
end if
end repeat
end tell
で動作するようにしようとしている私は、このコードの残りの部分は、ファイルにテキストを同期して追加するように見えることはできませんということです。私は、ターゲットファイルを直接指定すると(私は2番目のファイルを設定し、次にそのファイルにdoc2accessを設定しても、問題なく書くことができます)、私は '自動化された作成ステップからファイルを指定する方法について私の頭を抱かせるように思えます。
ここに私が見つけたコードは、ファイルへの書き込みで動作します。私は作成するファイルに書き込むためにそれを指定する必要があります。私が何をしたいか
set doc2access to (open for access file doc2 with write permission)
try
set z to -1
repeat until ((read doc2access from z for 1) is "}")
set z to z - 1
end repeat
write pasteText to doc2access starting at z
on error msg
display dialog msg buttons {"OK"} default button 1 with icon stop
end try
close access doc2access
は(スクリプトのこの部分の間に作成されたファイルのための変数である)ドキュメントこのNewNameを取ると、それにテキストを追加することです。それがcake1.txtのテキストファイルを作るのと同じように、cake1.txtに直接テキストを入れるコードを書くのではなく、テキストを使ってファイルを作成したいのです。
UPDATE は、私はあなたがすでに解決策を持って知っているが、私はちょうど私のコメントをバックアップしたい
tell application "Finder" to write pasteText to ((make file at aFolder with properties {name:NewName}) as alias)
あなたが本当にしたいですかAppleScriptでこれを行うには?これは非常に冗長で不器用で、macOSコンピュータでのみ動作します。ちょうど私の2セントですが、私は、MacOS、すべてのLinux/Unixコンピュータ、そしてWindows 10(明らかに)で動作する 'bash'を使うほうが良いと思います。あなたもあなたを助けることができるもっと多くの人々を見つけるでしょう。とにかく、 'Script2Text.rtf'のサンプルコンテンツを表示するのはどうですか?結果がどのようにして1つのイメージファイルを探すか。 –
私は使えるものがあり、私はこのMacでしばらくの間使っていますので、Applescriptを使っています。 Script2Textのテキストは無関係ですが、テキストをうまくコピーできます。コピーしたテキストを受け取るためのファイルを取得する方法を見つけることができます。ケーキ、パイ、アイスクリームを使った私の例は、単純すぎるものでした。私は実際にコピーしたテキストをテキストファイルにするだけで、コード化された名前(A8221、A8222、HS179など)を持つ数百のファイルを持っています。私はちょうどファイルが作成されたときに各ファイルにテキストをコピーする方法を見つける必要があります。 – medrob
すべてのファイルがそれらに書き込まれたScript2Textの内容全体を取得しない限り、テキストは無関係ではありません。彼らは? –