Wednesday, October 17, 2018

#1 2018-10-11 12:20:59 pm

ldicroce
Member
Registered: 2017-11-25
Posts: 64

Info on myself (as a script)

This might be a silly question, but ....why the first line of the script works and the other doesn't

Applescript:

my name
--> return the script name

my creation date
--> ERROR

Offline

 

#2 2018-10-11 01:11:30 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3267

Re: Info on myself (as a script)

As far as I know, name is a property of the script itself but creation date is a property of the file storing the script.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 11 octobre 2018 21:10:42

Offline

 

#3 2018-10-12 02:20:47 am

ldicroce
Member
Registered: 2017-11-25
Posts: 64

Re: Info on myself (as a script)

Yvan Koenig wrote:

As far as I know, name is a property of the script itself but creation date is a property of the file storing the script.


Applescript:

Interesting! Based on your input I did:
my name
--> return the script name. OK this is expected!
set collectedInfo to my properties
--> return a list of information

But now the info are on the application I use to edit/run the script. Among those, the "name" is now Script Debugger.

Offline

 

#4 2018-10-12 03:18:13 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3267

Re: Info on myself (as a script)

Applescript:

--Interesting! Based on your input I did:
my name
log result
--> return the script name. OK this is expected!
set collectedInfo to my properties
--> return a list of information about the editor

set scriptPath to path of document 1
tell application "System Events"
   set scriptCreationDate to creation date of disk item scriptPath
end telll

I got:
(*4ldicroce*)
tell application "Script Editor"
    get properties
        --> {selection:insertion point after character 180 of text of document "4ldicroce.scpt", frontmost:true, class:application, name:"Script Editor", version:"2.10"}
    get path of document 1
        --> "/Users/yvankoenig/Pictures/4ldicroce.scpt"
end tell
tell application "System Events"
    get creation date of disk item "/Users/yvankoenig/Pictures/4ldicroce.scpt"
        --> date "vendredi 12 octobre 2018 à 11:13:56"
end tell
Résultat :
date "vendredi 12 octobre 2018 à 11:13:56"

It seems logical except perhaps the fact that my name returns the name of the script while my properties return the properties of the application editing the script.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 12 octobre 2018 11:16:04

Offline

 

#5 2018-10-12 03:18:51 am

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

Re: Info on myself (as a script)

ldicroce wrote:

But now the info are on the application I use to edit/run the script. Among those, the "name" is now Script Debugger.


A script doesn't have its own identity until it's saved. Then its name is that of the script file without the extension — UNLESS you set a name property in the script code itself, in which case getting my name will return that instead of name of the file.

Applescript:

property name : "Fred"

my name


NG

Offline

 

#6 2018-10-12 03:34:48 am

ldicroce
Member
Registered: 2017-11-25
Posts: 64

Re: Info on myself (as a script)

I don't get it.

If I save the script, I get exactly the same with this script:

Applescript:

my name
-- name of the saved scritp on my desktop

set collectedInfo to my properties
-- multiple info in Script Debugger

my creation date
--> ERROR: Can’t get creation date.

Offline

 

#7 2018-10-12 04:21:27 am

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

Re: Info on myself (as a script)

Hi.

If you look in the AppleScript Language Guide, you'll see that AppleScript only defines class, name, id, and version properties for a script. It doesn't provide properties or modification date properties. If you're running a script inside either Script Debugger or Script Editor, my properties will return the scriptable properties of the editor. Neither a running script nor either of the editors has a modification date property. Only the files from which they're launched have that, so a script has to identify its own file and get the modification date from that.

Last edited by Nigel Garvey (2018-10-12 04:22:57 am)


NG

Offline

 

#8 2018-10-12 07:54:46 am

ldicroce
Member
Registered: 2017-11-25
Posts: 64

Re: Info on myself (as a script)

Thanks Nigel for clarifying this !

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)