Question: I'm curious if there's a way to “assign script” to an image inserted into a cell using the =IMAGE(“URL”) method for Google Sheets? If not, is there a way to “assign script” to a hyperlink? 

What I’d like to do is create a table of contents tab inside a Google Sheet that has many other tabs. On the table of contents, I’d love to have inserted images that act as buttons to navigate to these different tabs. I can “assign script” to images that have been inserted through the menu toolbar (e.g., Insert > Image or Insert > Drawing). However, it’s extremely clunky to have to realign my images if a new row is inserted into the table of contents.

I could always just use hyperlinks to navigate to each tab, but I don’t like how it opens a new window every time you click on the hyperlink. And I don’t like how it requires two clicks of a hyperlink (one click for the hyperlink, and then another click for the web address that pops up) to arrive at the desired tab.

So I guess, is there any option that exists to insert an image inside a cell, which can then be assigned a script?

This functionality would be so helpful.

Thanks for you time!

Answer: 
Thanks to @bteapot for suggesting I add the `-com.apple.CoreData.ConcurrencyDebug 1` argument to my scheme. I got more information on how this works from Ole Begemann's excellent [Core Data Concurrency Debugging](http://oleb.net/blog/2014/06/core-data-concurrency-debugging/) article.

Adding this flag causes an exception to be thrown as soon as your code calls into your `NSManagedObjectContext` from an incorrect thread. This works great in Xcode, but be advised that in an Xcode Bot, this causes tests to fail with this unhelpful message:

> 
> Lost connection to test manager service
> 
> 
>
I had this same issue and struggled with it all day today. Adding the concurrency debugging was a step in the right direction for me but the underlying issue was that I was attempting to access the same instance of a managed object context from different threads. The method causing my crash was trying to return a fetched object. I was able to fix it by wrapping my do, try, catch block in a context.perform block and make the method take an escaping closure as a parameter instead of returning the object.

```
func fetchUser(id: Int, completion: @escaping (User) -> ()) {
    let predicate = NSPredicate(format: "id = %d", id)
    let request: NSFetchRequest<User> = User.fetchRequest()
    request.predicate = predicate
    context.perform {
        // try to fetch user from core data
        do {
            if let user = try self.context.fetch(request).first {
                completion(user)
            } else {
                // if no user exists with that id, create and return a new user
                self.seedAutoPopulatingLists(for: id)
                completion(NSEntityDescription.insertNewObject(forEntityName: "User", into: self.context) as! User)
            }
        } catch let error as NSError {
            print("Could not fetch: \(error) \(error.userInfo)")
        }
    }
}

```

Hopefully this helps anyone running into this in the future.