Sunday, January 23, 2022

#1 2022-01-09 11:46:19 am

dooglesnak
Member
Registered: 2021-11-27
Posts: 55

Conflict with Foundation Framework

If I have "Foundation" in the scripts framework dependencies, this code returns the dialog "Can’t make current application into type file" and ends the script. The script runs successfully without the Foundation framework.

I'm halfway through troubleshooting the code, but haven't identified which part is causing the error. I ran into some issues the other day with AVFoundation/AVFAudio which were Catalina specific, could this be OS related? If not, any idea how I might be able to work around it?

The code works independently and doesn't rely on the rest of the script to run,  I'd rather not delegate it to another script.

Any advice would be greatly appreciated


Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions


property sourceFile : ((path to desktop) & "output.txt") as string
property dataFolder : ((path to desktop) & "dataFolder:") as string
property destFolder : ((path to desktop) & "./tempCsv:") as string


try
   set copyList to {}
   set suffixList to paragraphs of (read file sourceFile)
   
   set csvList to list folder dataFolder without invisibles
   
   repeat with n from 1 to count (csvList)
       set thisCsv to item n of csvList
       set fileRef to alias (dataFolder & thisCsv)
       repeat with suffixName in suffixList
           if (suffixName as string) is in thisCsv then
               set end of copyList to fileRef
               exit repeat
           end if
       end repeat
   end repeat
   
   display dialog "Analysis Complete, preparing " & return & (count copyList) & " references to be processed "
   tell application "Finder"
       duplicate copyList to folder destFolder
       
   end tell
   
end try

Model: 2019 2.9 or something xeon core 16gb
AppleScript: Script Debugger 8
Browser: Safari 605.1.15
Operating System: macOS 10.15

Last edited by dooglesnak (2022-01-09 11:54:23 am)


Filed under: Foundation

Offline

 

#2 2022-01-09 01:10:20 pm

dooglesnak
Member
Registered: 2021-11-27
Posts: 55

Re: Conflict with Foundation Framework

Its seems the specifier "file" in the read command is whats causing the conflict.

I've tried a few other things inncluding a suggestion from SD forum to use: "(read "variable" as «class furl»)" but on run either the script immediately stops or says "Can’t make "Mojave:Users:dh:Desktop:output.txt" into type file."

Last edited by dooglesnak (2022-01-09 01:50:36 pm)

Offline

 

#3 2022-01-09 04:37:42 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6747

Re: Conflict with Foundation Framework

dooglesnak wrote:

property sourceFile : ((path to desktop) & "output.txt") as string



First off, this is not a good idea. You're coercing two items to a string, which means using whatever the value of text item delimiters is as that point. Use "property sourceFile : ((path to desktop as text) & "output.txt")"

Two things to try.

First, use this approach:

Applescript:

property sourceFile : ((path to desktop as text) & "output.txt")
...
set sourceFile to sourceFile as «class furl»
...
set suffixList to paragraphs of (read sourceFile)

Note the word file has to be removed.

If that fails, try with a file not on the desktop, to check it's not a permissions problem.

Oh, and a third: remove that try block when testing. It only makes it harder to track down what's happening.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#4 2022-01-10 03:18:09 am

dooglesnak
Member
Registered: 2021-11-27
Posts: 55

Re: Conflict with Foundation Framework

Thanks very much Shane, it works great. I thought I was going to have to use mdfind but the search cross referenced 200 files against 3000 in just over 10 seconds Not bad at all.

Thanks again!

Doug

Offline

 

#5 2022-01-10 04:22:19 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5474

Re: Conflict with Foundation Framework

Shane Stanley wrote:
dooglesnak wrote:

property sourceFile : ((path to desktop) & "output.txt") as string



First off, this is not a good idea. You're coercing two items to a string, which means using whatever the value of text item delimiters is as that point. Use "property sourceFile : ((path to desktop as text) & "output.txt")"


Another reason it's not a good idea is that by making 'sourceFile' a property, you're setting it to the path at the time you compile the script rather than the path at the time the script's run. If you later want to run the script in a situation where the disk or user names are different, you'll have to recompile it before it will work. It's better to use path to desktop at run time instead:

Applescript:

-- property sourceFile:((path to desktop as text) & "output.txt") -- Ditch this.

set sourceFile to ((path to desktop as text) & "output.txt") as «class furl»


NG

Offline

 

#6 2022-01-10 06:15:48 am

dooglesnak
Member
Registered: 2021-11-27
Posts: 55

Re: Conflict with Foundation Framework

Great, ok. Thank you Nigel!

Doug

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)