LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
kaveh1000
- Livecode Opensource Backer

- Posts: 539
- Joined: Sun Dec 18, 2011 7:23 pm
-
Contact:
Post
by kaveh1000 » Fri Dec 10, 2021 9:52 pm
Hi all. Here is my script for a button to copy a file into a subdirectory of the original file.
Code: Select all
on mouseup
answer file "Please select an image file" as sheet
put it into tFile
set the itemDelimiter to "/"
-- grab file name
put the last item of tFile into tFileName
put item 1 to -2 of tFile into tCurrentFolder
put tCurrentFolder & "/" & "temp/" into tDestinationFolder
revCopyFile tFile, tDestinationFolder
answer the result
end mouseup
I get a result of
execution error. I am on a Mac and looking at previous posts I understand that this is an AppleScript error. Can anyone tell me what I am missing?
Minimal stack attached.
-
Attachments
-
- copy file.livecode.zip
- (979 Bytes) Downloaded 161 times
Kaveh
-
Klaus
- Posts: 14189
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Sat Dec 11, 2021 12:21 am
Hi Kaveh,
I never used revcopyfile, I always let LC do this kind of actions.
Do this:
Code: Select all
on mouseup
answer file "Please select an image file" as sheet
put it into tFile
set the itemDelimiter to "/"
-- grab file name
put the last item of tFile into tFileName
## Now create target filename:
put tFile into tTargetFile
## We simply overwrite that pathname:
put ("temp/" & tFileName) into last item of tTargetFile
## Now use put url binfile... to let LC copy that thing:
put url("binfile:" & tFile) into url("binfile:" & tTargetFile)
## No uneccessary alerts... ;-)
if the result <> EMPTY then
answer ("TOOT TOOT TOOT" & CR & the result)
end if
end mouseup
Best
Klaus
-
bn
- VIP Livecode Opensource Backer

- Posts: 4171
- Joined: Sun Jan 07, 2007 9:12 pm
Post
by bn » Sat Dec 11, 2021 9:47 am
Hi Kaveh,
I tried your script and it did not work for me. Then I was wondering if it is a permission problem. I am using MacOS 10.14.4 Mojave.
I copied the script that LC makes for AppleScript
Code: Select all
tell application "Finder"
duplicate file "root:Users:user:Desktop:Bildschirmfoto 2021-11-19 um 12.17.12.png" to folder "root:Users:user:Desktop:temp"
return the result as text
end tell
And tried to run it from "ScriptDebugger" an application for debugging appleScript.
ScriptDebugger put up a dialog "You have to give ScriptDebugger permission to access "Finder" in order to run this script"
After I granted ScriptDebugger permission the script worked and did the copying.
So my conclusion is that LC does not have permission to acccess "Finder" for revcopyfile to work.
Permissions get to be more and more restrictive and confusing.
Kind regards
Bernd
Last edited by
bn on Sat Dec 11, 2021 11:03 am, edited 1 time in total.
-
bn
- VIP Livecode Opensource Backer

- Posts: 4171
- Joined: Sun Jan 07, 2007 9:12 pm
Post
by bn » Sat Dec 11, 2021 10:15 am
@Kaveh,
I played with permissions for LC in "Security" in "System Settings" of the Mac and it turned out that if I grant LC permission to use "Automation" and allow Finder access then your script works fine from the IDE.
Kind regards
Bernd
-
kaveh1000
- Livecode Opensource Backer

- Posts: 539
- Joined: Sun Dec 18, 2011 7:23 pm
-
Contact:
Post
by kaveh1000 » Sat Dec 11, 2021 2:15 pm
Thank you Klaus and Bernd for your suggestions.
Looks like Apple is making it hard for Apps to use the finder...
I added LiveCode to permissions for automation (see shot) but still get an error and no file copied.
Meanwhile I am trying to use Klaus' method but again getting error. Getting the Toot Toot message you put in. I don't know how to debug it. I tried
Code: Select all
put url("binfile:" & tFile) into tURL
put tURL
put tURL into url("binfile:" & tTargetFile)
but of course it is a binary file. Any suggestions?
-
Attachments
-

Kaveh
-
Klaus
- Posts: 14189
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Sat Dec 11, 2021 2:18 pm
Waht does the dialog tell you except "TOOT TOOT TOOT"?
To be sure:
You already HAVE a folder named "temp" in the same folder containing the image file(s)?
-
bn
- VIP Livecode Opensource Backer

- Posts: 4171
- Joined: Sun Jan 07, 2007 9:12 pm
Post
by bn » Sat Dec 11, 2021 2:19 pm
Hi Kaveh,
the screenshot does not show the permissions for "Automation"
Kind regards
Bernd
-
kaveh1000
- Livecode Opensource Backer

- Posts: 539
- Joined: Sun Dec 18, 2011 7:23 pm
-
Contact:
Post
by kaveh1000 » Sat Dec 11, 2021 2:23 pm
Sorry. Attached is Automation. I cannot see how I can add more Apps to it. No + sign below.
-
Attachments
-

Kaveh
-
bn
- VIP Livecode Opensource Backer

- Posts: 4171
- Joined: Sun Jan 07, 2007 9:12 pm
Post
by bn » Sat Dec 11, 2021 2:28 pm
Attached is Automation. I cannot see how I can add more Apps to it. No + sign below.
Try to give LC permission to access the "hardDisk", then it will show up in "Automation" (I hope)
Kind regards
Bernd
-
kaveh1000
- Livecode Opensource Backer

- Posts: 539
- Joined: Sun Dec 18, 2011 7:23 pm
-
Contact:
Post
by kaveh1000 » Sat Dec 11, 2021 4:05 pm
Added to full disk access but still not appearing in Automation

-
Attachments
-

Kaveh
-
bn
- VIP Livecode Opensource Backer

- Posts: 4171
- Joined: Sun Jan 07, 2007 9:12 pm
Post
by bn » Sat Dec 11, 2021 4:58 pm
I don't know why it does not work. You seem to be on a more recent MacOS than I am.
The script I used is
Code: Select all
on mouseup
answer file "Please select an image file" as sheet
put it into tFile
set the itemDelimiter to "/"
-- grab file name
put the last item of tFile into tFileName
put item 1 to -2 of tFile into tCurrentFolder
put tCurrentFolder & "/" & "temp" into tDestinationFolder
if there is a folder tDestinationFolder then
revCopyFile tFile, tDestinationFolder
else
create folder tDestinationFolder
revCopyFile tFile, tDestinationFolder
end if
answer the result
end mouseup
Kind regards
Bernd
-
kaveh1000
- Livecode Opensource Backer

- Posts: 539
- Joined: Sun Dec 18, 2011 7:23 pm
-
Contact:
Post
by kaveh1000 » Sat Dec 11, 2021 5:02 pm
Thanks Bernd
Just tried that exact script. I get a folder created so that is some progress. But no file, and I get "execution error".
Kaveh
-
Klaus
- Posts: 14189
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Sat Dec 11, 2021 5:19 pm
AHA!
That explains why my script did not work for you, it tried to access a non-existing folder.
Maybe you could supply a tad more info next time...
This should do the trick:
Code: Select all
on mouseup
answer file "Please select an image file" as sheet
put it into tFile
set the itemDelimiter to "/"
-- grab file name
put the last item of tFile into tFileName
## Now create target filename:
put tFile into tTargetFile
## We simply overwrite that pathname:
## Fist check for existence of folder TEMP
put "temp" into last item of tTargetFile
## Create if neccessary:
if NOT (there is a folder tTargetFile) then
create folder tTargetFile
end if
## Create the final filename:
put ("/" & tFileName) AFTER tTargetFile
## Now use put url binfile... to let LC copy that thing:
put url("binfile:" & tFile) into url("binfile:" & tTargetFile)
## No uneccessary alerts... ;-)
if the result <> EMPTY then
answer ("TOOT TOOT TOOT" & CR & the result)
end if
end mouseup
-
kaveh1000
- Livecode Opensource Backer

- Posts: 539
- Joined: Sun Dec 18, 2011 7:23 pm
-
Contact:
Post
by kaveh1000 » Sat Dec 11, 2021 5:27 pm
It works!!!!!!!!!!!!!
Thank you so much Klaus. I understand now. My assumption was it would make the folder on the fly!
This is great. I will go thro the script carefully and work on it further and come back with any questions.
Thanks again and to Bernd
Enjoy Sunday.
Regards
Kaveh
Kaveh