Finder "isn't running"

Hi, I have a bizarre issue. This script:

tell application "Finder"
			tell me to log 3
			activate
			tell me to log 4

Makes this log:

I don’t even know what to think.

Hey Richard,

What OSX are you running?

What Applescript Editor are you running from?

Where are you seeing this log entry? In the Applescript Editor, the Console, or elsewhere?

Why are you using tell me to log 3 rather than simply log 3?

Have you tried relaunching the Finder? (Option-Control-Click in the Finder icon in the Dock.)

Have you tried relaunching the Applescript Editor?

Have you tried rebooting your system?

I suspect the Finder quitting is happening in earlier code we can’t see. Just because you’re seeing the 3 logged doesn’t mean the Finder is running at that point.

Hi guys, thanks for replying

The purpose of logging numbers is to find which line of code caused the errors, and the activate line is just there to prove that the error happens on the first thing you tell Finder in the tell statement, I don’t actually need to activate it.

I’m on 10.8, and I did post in the right forum :wink: this is Xcode (the latest official versions).

Here’s the whole subroutine:

on subaddtype_(sender)
		if (valwintypeaddgen's indexOfSelectedItem()) is 0 then
			display dialog "Please select a genre." buttons {"OK"} default button 1 with icon caution with title "Dialog Maker"
			return
		end if
		--get extension
		set valnewtypenam to (valwintypeaddnam's stringValue()) as string
		--fix dot
		repeat
			if valnewtypenam starts with "." then
				try
					set valnewtypenam to text 2 thru -1 of valnewtypenam
				end try
			else
				set valnewtypenam to "." & valnewtypenam
				exit repeat
			end if
		end repeat
		--check name against existing
		set valtypelist to {}
		repeat with valreptype in valbwindata
			set valtypelist to valtypelist & (valbwinfile of valreptype)
		end
		if valnewtypenam is "." or valnewtypenam is in valtypelist then
			display dialog "Please choose a valid file type name that doesn't exist here." buttons {"OK"} default button 1 with icon Caution with title "Dialog Maker"
			return
		end

		--get identifier
		
		set valmytempdir to (path to temporary items as string) --text 1 thru -16 of
		set valmytempdir to posix path of valmytempdir
		
		set valfile to ((valmytempdir & text 2 thru -1 of valnewtypenam & valnewtypenam) as posix file) as string
		log "file: " & valfile
		--create file with new type
		tell current application
			open for access file valfile with write permission
			log 1
			close access file valfile
			log 2
		end tell
		tell application "Finder"
			tell me to log 3
			activate
			tell me to log 4
			set valident to file type of (info for file valfile)
			tell me to log valident
			if valident is "TEXT" then
				set valident to type identifier of (info for file valfile)
				tell me to log valident
				if valident is "com.apple.traditional-mac-plain-text" then
					set valident to text 2 thru -1 of valnewtypenam
					tell me to log valident
				end if
			end if
		end tell
		--register new type
		set valnewtype to {{valbwinfile:valnewtypenam, valbwingen:(valwintypeaddgen's titleOfSelectedItem()) as string, valbwinallo:false, valbwinident: valident}}
		log 4
		set valcusttypes to valcusttypes as list & valnewtype
		log 5
		valgloprefs's setObject_forKey_(valcusttypes,"typesprefs")
		set my valbwindata to valdeftypes & valcusttypes
	end subaddtype_

When I run, type in “test” and click, this is the whole log:

So what happens if you try to tell the Finder to do something earlier on?

This exact error happens to whatever the first line of Finder code is.

Could sandboxing be to blame here? I can’t think of anything else, but I thought all Apple Events were allowed for us, so it shouldn’t be an issue.

Right, but what happens if you add a tell Finder block earlier in the handler?

Yep, same thing, first line.
I also just found that it’s happening to AppleScript Editor when my app asks for a document name. I guess it must be sandboxing??? :confused:

Are you sandboxing your app?

Sadly I have to, although I appreciate what Apple is doing.

Then your choice is to give yourself the appropriate temporary exceptions, or – more usefully – stop using the Finder and use NSWorkspace, NSURL and/or NSFileManager to get the info you need.

So I need temporary exceptions to script other apps now? How?
And do they need to be “temporary”?

Yes, add the appropriate entitlement keys

Yes, it’s a part of the required terminology and described in the documentation

I agree with Shane

You will get the requested information without AppleScript / temporary exceptions.
From my own experience Apple will reject applications with too many “useless” entitlements

Hi, I read the docs, can you explain the difference between the “com.apple.security.scripting-targets” one and “com.apple.security.temporary-exception.apple-events”, it’s not well explained. I read the sdef man page too, I don’t understand what the access groups are, or at least how to find them.

I think it’s working now, thank you so much! (I had to dig around to find the name of AppleScript Editor is now scripteditor2 - weird!)

I will look into using cocoa for my next update :slight_smile:

com.apple.security.temporary-exception.apple-events is for the ability to send apple events to one or multiple apps. This entitlement affects the entire scripting dictionary

com.apple.security.scripting-targets can be used only for apps which support scripting access groups defined in the sdef file. Scripting access groups is a new feature introduced in 10.8
This entitlement affects only the specified group(s) of the scripting dictionary

Thanks! But I don’t know how to find the access groups from what the docs say…

The access groups are supposed to be specified in the scripting definition file at design time.
The user is not able to create or change those groups.

As far as I know only iTunes and Mail support scripting access groups

If they’re supposed to be listed in the dictionary, I can’t find them. (for mail)

You will have to look at the sdef file directly – it should be in the Mail bundle’s Resources folder.

Thank you!!! :smiley: