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
> 
> 
>
In swift 5

Create Persistence container

```
private final class PersistanceContainerProvider  {
    var container: NSPersistentContainer = {
        let container = NSPersistentContainer(name: "Test")
        container.loadPersistentStores(completionHandler: { storeDescription, error in
            if let error = error as NSError? {
                fatalError("Unable to load persistance store")
            }
        })
        return container
    }()
}

```

Created ManagedContext with background concurrency

```
private init(persistentContainerProvider: DefaultPersistanceContainerProvider = PersistanceContainerProvider()){
        self.persistentContainer = persistentContainerProvider.container
        self.managedObjectContext = persistentContainer.newBackgroundContext()
        print("Wasim \(self.managedObjectContext.concurrencyType.rawValue)")
    }

```

Apply managedObjectContext.performAndWait

```
func addTargetCode(symbol: Symbol) {
        managedObjectContext.performAndWait {
        do {
            if let existing = try managedObjectContext.fetch(ManagedTargetCurrency.fetchRequest(by: symbol.code)).first {
                existing.code = symbol.code
                existing.name = symbol.name
                 try save()
            } else {
                let added = (NSEntityDescription.insertNewObject(forEntityName: ManagedTargetCurrency.entityName, into: managedObjectContext) as? ManagedTargetCurrency).require(hint: "Wrong Core Data Configuration?")
                added.code = symbol.code
                added.name = symbol.name
                 try save()
            }
        } catch let error {
            print(Errors.addError(cause: error))
        }
        }
    }

```