Sunday, December 4, 2022

#1 2022-11-04 08:37:29 am

Joy
Member
From:: Tirol
Registered: 2008-07-04
Posts: 689

Verify applications

To verify applications in Terminal is not an issue, but how can I get same results in Applescript?

Applescript:

set appSig to (do shell script "codesign -dv /Applications/Books.app")

Offline

 

#2 2022-11-05 12:18:43 pm

robertfern
Member
Registered: 2011-11-29
Posts: 225

Re: Verify applications

Since Big Sur, the Mac has 2 partitions of the boot drive that are merged at runtime.
This is for security reasons. The "System" part contains all the OS and OS included applications.
There the "Book.app" is really in location "/System/Applications/"
User installed apps are in "/Applications/".

so the AppleScript is

Applescript:

set appSig to do shell script "codesign -dv /System/Applications/Books.app 2>&1"

had to set stderr to stdout to get the results

Last edited by robertfern (2022-11-07 10:21:46 am)

Offline

 

#3 2022-11-08 10:23:23 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2589

Re: Verify applications

Joy wrote:

To verify applications in Terminal is not an issue, but how can I get same results in Applescript?

Applescript:

set appSig to (do shell script "codesign -dv /Applications/Books.app")


Maybe, your application doesn't open due to other reason as well. Try to remove gatekeeper quarantine as additional step. This step is useful for applications from unknown (to Apple) developers. Example I use for my Mac:

Applescript:


set theApp to ((path to applications folder) as text) & "Avidemux_2.7.8.app"
set appPosixPath to POSIX path of theApp
set quotedPath to quoted form of appPosixPath
do shell script "xattr -rd com.apple.quarantine " & quotedPath with administrator privileges


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 15.6.1
Ram: 4 GB

Offline

 

#4 2022-11-13 01:36:16 pm

Joy
Member
From:: Tirol
Registered: 2008-07-04
Posts: 689

Re: Verify applications

Thanks to both for your awesome suggestions,

My problem is, i get an empty string in "Script Editor" like this:

Applescript:


Tell current application
do shell script "codesign -dv /Applications/Books.app"
--> ""

Meanwhile i get a normal and complete  output in "Terminal"
It doesn't matter what app i check with "Script Editor", results are always empty and results in Terminal are always complete

Offline

 

#5 2022-11-13 02:29:48 pm

robertfern
Member
Registered: 2011-11-29
Posts: 225

Re: Verify applications

WOW.

It seems you didn't read any of my previous post which explains this.

For Big Sur or newer...

Applescript:

do shell script "codesign -dv /System/Applications/Books.app 2>&1"

or on older OSes

Applescript:

do shell script "codesign -dv /Applications/Books.app 2>&1"

Last edited by robertfern (2022-11-13 02:34:39 pm)

Offline

 

#6 2022-11-13 02:59:55 pm

Fredrik71
Member
Registered: 2019-10-23
Posts: 1091

Re: Verify applications

@Joy
You could run this code... to get the path on your system.

Applescript:

use framework "AppKit"
use framework "Foundation"
use scripting additions

tell application "Books" to set bundleId to its id
set workspace to current application's NSWorkspace's sharedWorkspace()
((workspace's URLForApplicationWithBundleIdentifier:bundleId)'s valueForKey:"path") as string


Node-RED makes it easy to automate IoT

Offline

 

#7 2022-11-13 04:15:13 pm

robertfern
Member
Registered: 2011-11-29
Posts: 225

Re: Verify applications

or  you could just use regular AppleScript

Applescript:

POSIX path of (path to application "Books")

so the full script line would be (for all OS versions)

Applescript:

do shell script "codesign -dv " & (POSIX path of (path to application "Books")) & " 2>&1"

Last edited by robertfern (2022-11-13 04:21:40 pm)

Offline

 

#8 2022-11-14 12:36:10 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2589

Re: Verify applications

robertfern wrote:

or  you could just use regular AppleScript

Applescript:

POSIX path of (path to application "Books")

so the full script line would be (for all OS versions)

Applescript:

do shell script "codesign -dv " & (POSIX path of (path to application "Books")) & " 2>&1"


Yes, quite strange indeed. I confirm that all your scripts on this topic gives me the desired result. It's weird to think that they only works for the two of us.

Regarding the Posix path of app: it can be retrieved  without application launching as well. Also, quoted form is preferable:

Applescript:


on codeSignInfoFor:appName
   set bundleID to id of application appName
   tell application "Finder" to set appHFSpath to application file id bundleID as Unicode text
   set appQuotedPosixPath to quoted form of POSIX path of appHFSpath
   do shell script "codesign -dv " & appQuotedPosixPath & " 2>&1"
end codeSignInfoFor:

my codeSignInfoFor:"Safari"

Last edited by KniazidisR (2022-11-14 12:57:08 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 15.6.1
Ram: 4 GB

Offline

 

#9 2022-11-14 11:01:55 am

robertfern
Member
Registered: 2011-11-29
Posts: 225

Re: Verify applications

Thanks KniazidisR,

Here is a slightly different version that uses 'System Events' instead of 'Finder'

**EDIT** having problems , found bug

Applescript:

   tell application "System Events" to set myApp to application "Books"
   set appQuotedPosixPath to quoted form of POSIX path of (path to myApp)
   do shell script "codesign -dv " & appQuotedPosixPath & " 2>&1"

Only problem with 'System Evemts' is you have to hard code the app name. You can't use a variable or it will error out.


**EDIT** - crap, it still is launching the app. DAM, I tried

Last edited by robertfern (2022-11-14 11:20:25 am)

Offline

 

#10 2022-11-14 12:21:12 pm

Fredrik71
Member
Registered: 2019-10-23
Posts: 1091

Re: Verify applications

robertfern wrote:

Only problem with 'System Evemts' is you have to hard code the app name. You can't use a variable or it will error out.



Are you sure wink

Applescript:

set appNames to (choose from list {"App Store", "Books", "Calendar", "Mail"}) as string
set theName to a reference to application appNames
tell application "System Events" to set myApp to theName
set appQuotedPosixPath to quoted form of POSIX path of (path to myApp)
end
return appQuotedPosixPath


Node-RED makes it easy to automate IoT

Offline

 

#11 2022-11-14 01:48:14 pm

robertfern
Member
Registered: 2011-11-29
Posts: 225

Re: Verify applications

But the App still launches

Last edited by robertfern (2022-11-14 01:50:45 pm)

Offline

 

#12 2022-11-14 02:36:32 pm

Fredrik71
Member
Registered: 2019-10-23
Posts: 1091

Re: Verify applications

The only tell block I have in this example is to tell Books to quit.

Applescript:

set appName to "Books"
set appPath to a reference to path to application appName
try
   tell application "Books" to quit
end try
return POSIX path of (appPath as text)

And this lead me to... smile

Applescript:

set appName to (choose from list {"Books", "Calculator", "Notes"}) as string
set appPath to a reference to path to application appName
try
   tell application appName to quit
end try
return POSIX path of (appPath as text)

Ps. path to belongs to standard additions so it doesn't need a tell block.

Last edited by Fredrik71 (2022-11-14 02:43:41 pm)


Node-RED makes it easy to automate IoT

Offline

 

#13 2022-11-14 04:49:57 pm

Joy
Member
From:: Tirol
Registered: 2008-07-04
Posts: 689

Re: Verify applications

@robertfern

Ops, i skimmed your post and didn't notice you redirected the output to stdout.
Now it's working smile
Thanks again to everyone

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)