0

Good evening all, I am trying to understand why I can run the below script in Applescript Editor but am unable to successfully run it in an Xcode Cocoa-Applescript application.

Can someone please explain why this function will not run in Xcode and what I need to do to have it run correctly?

set this_data to ((current date) as string) & space & "WHY DOESN'T THIS LOG!!!!" & return
set this_file to (((path to desktop folder) as string) & "MY LOG FILE")
my write_to_file(this_data, this_file, true)


on write_to_file(this_data, target_file, append_data)
 try
    set the target_file to the target_file as string
    set the open_target_file to open for access file target_file with write permission
    if append_data is false then set eof of the open_target_file to 0
    write this_data to the open_target_file starting at eof
    close access the open_target_file
    return true
 on error
    try
        close access file target_file
    end try
    return false
 end try
end write_to_file

1 Answer 1

1

This is one of the Xcode behaviours I can't explain, but it works if you add tell current application like this:

tell current application to set the open_target_file to open for access file target_file with write permission

It might be better to put the whole function in a tell current application block.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.