RevCopyFile or URL and system Alert sounds

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

RevCopyFile or URL and system Alert sounds

Post by Simon Knight » Fri Jul 17, 2020 9:08 am

Hi,

The background to this question is that I am creating an application to run on my Apple MAc and for my own use that copies image files from a camera memory card to a selected folder on a hard drive. The app is not trying to replace the Finder but presents the image files grouped by shoot date to allow me to add key words to the file name along with performing a rename of each of the files. There may be thousands of images on the card plus xmp files.

The dictionary suggests that there are two methods of conducting a rename : revCopyFile or Put URL into URL_B. It also states that the revCopyFile has certain advantages one being :
It also does not require reading the entire file into memory, so even extremely large files can be copied.
The implication is that the URL command reads the whole file into memory before writing it out again. The image files I am working with are no larger that 25 Mbytes and there are few anywhere over say 100 Mbyte so reading the whole file into memory is not a great problem except it seems to slow the copy process down. My guess is that revCopyFile copies small bite size portions which speeds the process up. I wonder if any of you have had similar results or any comments?

So its seems like a win for revCopyFile. However, there is an issue: when each file copy operation completes the OS makes a "dedah" sound. This means that the computer gets very noisy as thousands of files are copied. The sound can be switched off by going to the System Prefs dialog and un-checking the "Play user interface sound effects".
Alerts.png
I would like to do this for the period that the copy op is running and wonder if anyone can direct me to either a Livecode command or a Shell command that does this?
best wishes
Skids

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: RevCopyFile or URL and system Alert sounds

Post by bogs » Fri Jul 17, 2020 2:25 pm

This page lists some of the shell commands involving volume (but you would need sudo priviledges).

Another tack you might take is just to mute the volume during the period where the copy routine is running, but that also appears to be a root directory level thing, as this page says.

Controlling actual system sounds from Lc appears to be mobile only option though.
Image

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9838
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: RevCopyFile or URL and system Alert sounds

Post by FourthWorld » Fri Jul 17, 2020 5:34 pm

There is a third way: you can open the source file, open a destination file, read the source in chunks, write the chunks to the destination, then close both with you're done.

https://livecode.com/resources/api/#liv ... /open_file
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4002
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: RevCopyFile or URL and system Alert sounds

Post by bn » Sat Jul 18, 2020 1:09 am

Hi Simon,

If you just want to turn off the system sound then you could do that using AppleScript on MacOSX


Here is an example stack that you could build into your stack. Use the fields of the stack as source of AppleScript.
I think the stack is pretty self-explanatory. It works for me on MacOSX 10.12.6

Kind regards

Bernd

MuteMacOSX.livecode.zip
(1.4 KiB) Downloaded 176 times

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: RevCopyFile or URL and system Alert sounds

Post by Simon Knight » Sat Jul 18, 2020 7:45 am

Thanks for the ideas. I've decided to use URL as it also allows file renaming as part of a single call so simplifies my code. However I have put the creation of a file copy widget on my list of to dos.

Bernd's reply prompted me to look at Applescript, so thats an hour and a half I have lost ;-). To use Applescript it seems that I need two almost identical scripts one to switch alert sounds off, the second to switch them back on. A third would probably be a good idea just to return the state of the check box, but I have not written it.

So here is my Applescript:

Code: Select all

if running of application "System Preferences" then
	quit application "System Preferences"
	delay 1
end if


tell application "System Preferences"
	reveal pane id "com.apple.preference.sound"
	delay 1
	tell application "System Events"
		tell tab group 1 of window "Sound" of application process "System Preferences"
			tell checkbox "Play user interface sound effects"
				if value is equal to 1 then click it
			end tell
		end tell
	end tell
end tell
I based the script on examples found on stackoverflow so have no idea why the delay commands are deemed a good idea. The hard part is identifying how to address the required window element i.e checkbox "name" of tab group 1 etc etc. For this I found a really useful script :

Code: Select all

tell application "System Events"
	tell front window of (first application process whose frontmost is true)
		set uiElems to entire contents
	end tell
end tell
To use create some Applescript that opens the Apple window you wish to make changes to, system prefs sound in my case. Place the three lines (above) below your code, compile and run. Once run the results window will list every element in the front window and its just a case of looking for the element you want to change. The check box I am using was listed as:
checkbox "Play user interface sound effects" of tab group 1 of window "Sound" of application process "System Preferences"
Here is a screen shot of a portion of the results pane from Script Debugger V6 when the code snip is added.
It returned 92 elements in all.
Screenshot 2020-07-18 at 07.37.28.png
ResultsPAne
I hope someone will find this useful, even if no one does at least I will be able to find it again when I have forgotten how I created the Applescript in two weeks time!

best wishes

Simon
best wishes
Skids

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4002
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: RevCopyFile or URL and system Alert sounds

Post by bn » Sat Jul 18, 2020 8:01 am

Simon Knight wrote:
Sat Jul 18, 2020 7:45 am
Bernd's reply prompted me to look at Applescript, so thats an hour and a half I have lost ;-).
Simon,

The scripts in the stack I posted should have worked for just muting temporarily. Did they not work?
(By the way I also use ScriptDebugger, extremely useful when working with AppleScript)

Kind regards
Bernd

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: RevCopyFile or URL and system Alert sounds

Post by Simon Knight » Sat Jul 18, 2020 8:12 am

Hi Bernd,

Of course your scripts work!

My reason is that I spent sometime yesterday trying to discover a method of changing the Alert Sounds status from the command line. So far I have not found anything so when I read your reply I thought I would give it a try using Applescript and my post is what I have come up with.

Obviously my script is more complex but it does have the advantage of allowing most sound to work while a lengthy copy operation takes place.
best wishes
Skids

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4002
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: RevCopyFile or URL and system Alert sounds

Post by bn » Sat Jul 18, 2020 8:57 am

Hi Simon,

I was lazy last night and did not search for alert sounds. (I usually go to MacScripter.net)

Here is a simple version to turn off just _Alert_ sound. It is just for alerts. You can still listen to your music.
All taken from MacScripter.net

Code: Select all

set originalVolume to alert volume of (get volume settings)
set volume alert volume 0
return originalVolume

Code: Select all

set volume alert volume 55
Kind regards
Bernd
MuteAlertVolumeMacOSX.livecode.zip
(1.48 KiB) Downloaded 199 times

Post Reply

Return to “Talking LiveCode”