Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 3760 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

So I have a working native applescript already:

 

set stringToFind to """

set stringToReplace to ""

set theFile to choose file

set theContent to read theFile as «class utf8»

set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, stringToFind}

set ti to every text item of theContent

set AppleScript's text item delimiters to stringToReplace

set newContent to ti as string

set AppleScript's text item delimiters to oldTID

try

set fd to open for access theFile with write permission

set eof of fd to 0

write newContent to fd as «class utf8»

close access fd

on error

close access theFile

end try

 

I want to eliminate the "choose file" step at the beginning since the file location is in a filemaker variable already, but if I change to it being a calculated script (only major changes in the first three lines):

 

"set stringToFind to """¶
set stringToReplace to ""¶
set theFile to " & Quote($filePath) & "¶
set theContent to read theFile as «class utf8»¶
set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, stringToFind}¶
set ti to every text item of theContent¶
set AppleScript's text item delimiters to stringToReplace¶
set newContent to ti as string¶
set AppleScript's text item delimiters to oldTID¶
try¶
    set fd to open for access theFile with write permission¶
    set eof of fd to 0¶
    write newContent to fd as «class utf8»¶
    close access fd¶
on error¶
    close access theFile¶
end try"
 
I get the error: "Expected end of line, etc. but found identifier."
Posted

I figured it out. I don't have "tell" blocks. The native script worked because without a tell block it assumes to mean you are telling the Finder, but for calculated applescripts it assumes you are telling Filemaker. Changing to :

 

tell application "Finder"
    --my code
end tell

 

fixed it

This topic is 3760 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.