Tuesday, September 29, 2020

#1 2020-07-04 02:17:34 pm

MitchBVI
Member
Registered: 2006-02-14
Posts: 197

Changing the Download Folder in Safari

I have a short routine that changes the download folder location in safari. What follows works but seems very clumsy any suggestions?

Thanks

Applescript:


--ChangeDownloadFolder.scpt
--1st Choose the Folder that is to be the destination for Downloads
set Dfolder to (choose folder) as string
set Dfolder to POSIX path of Dfolder
set Dfolder to Dfolder & "\""

tell application "Safari" to quit
delay 0.5
do shell script "defaults write com.apple.safari DownloadsPath -string \"" & Dfolder
--The following sequence is very clumsy but seems at present to be necessary
tell application "Safari" to activate
delay 0.5
tell application "Safari" to quit
delay 0.5
tell application "Safari" to activate
delay 0.5

Model: MacBook Pro
AppleScript: 2.7
Browser: Safari 605.1.15
Operating System: macOS 10.13

Offline

 

#2 2020-09-15 05:28:49 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 1311

Re: Changing the Download Folder in Safari

Why all these quit-->activate-->quit-->activate and delay-->delay-->delay without understanding what they does?
I already showed you the code 4 months ago. That is, how to do it. Okay, I'll repeat the code with additional explanations.

Applescript:


-- 1st Choose the Folder that is to be the destination for Downloads
set downloadsFolder to quoted form of POSIX path of (choose folder)

-- If do not quit the "Safari", the changes you make in the defaults will be ignored.
-- So, quit Safari. Once only. What need quit start 4 times as you do?...
tell application "Safari" to quit

-- The Safari doesn't quit immediatelly, so check when it quits fully, using repeat loop
-- One delay only here is need. You should understand - this makes the script stable... Nothing more.
tell application "System Events"
   repeat while application process "Safari" exists
       delay 0.1
   end repeat
end tell

-- make the changes in the defauts
do shell script ("defaults write com.apple.Safari DownloadsPath " & downloadsFolder)

-- the change is made. But you can open "Safari" to see in its Preferences that I am not lying
tell application "Safari" to activate

Last edited by KniazidisR (2020-09-15 05:29:58 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#3 2020-09-15 12:22:33 pm

MitchBVI
Member
Registered: 2006-02-14
Posts: 197

Re: Changing the Download Folder in Safari

Thank you and my apologies, its 60 years since I was hardwiring IBM 501's  and my memory fails me at times. I have started an AppleScript utility file so hopefully will not make the same mistake again.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)