Tuesday, November 19, 2019

#1 2019-11-06 09:57:49 am

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

Effectively create temp folder in temp Items of user domain

Applescript:


set folderName to quoted form of "myRandomNameFolder"
set _tempFolder to do shell script "mktemp -d -t " & folderName

-- The code bellow is only to make visible result of code above
tell application "Finder"
   activate
   select (_tempFolder as POSIX file)
end tell
delay 10


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

#2 2019-11-06 06:16:08 pm

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

Re: Effectively create temp folder in temp Items of user domain

Here's an alternative using ASObjC and a UUID:

Applescript:

use framework "Foundation"
use scripting additions

set fileManager to current application's NSFileManager's defaultManager()
set theURL to fileManager's temporaryDirectory()'s URLByAppendingPathComponent:(current application's NSUUID's UUID()'s UUIDString())
fileManager's createDirectoryAtURL:theURL withIntermediateDirectories:true attributes:(missing value) |error|:(missing value)
return theURL's |path|() as string

A little more anonymity and speed.


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

Offline

 

#3 2019-11-06 10:33:09 pm

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

Re: Effectively create temp folder in temp Items of user domain

Thanks Snane for your code. Your code will come in handy in many scripts, as this is one of the fundamental tricks of every programmer. I will keep both successful variants in my library. And... your variant is, of course, better. smile

Most of all I liked the name of the folder. Here it is: "C0D92014-CD4B-4CD9-9CED-526240E1C249."

Last edited by KniazidisR (2019-11-06 10:36:23 pm)


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

#4 2019-11-07 12:04:35 am

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

Re: Effectively create temp folder in temp Items of user domain

KniazidisR wrote:

Most of all I liked the name of the folder.



That's a UUID, or universally unique identifier. It's a 128-bit number that's unique for practical purposes.


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

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)