Question: I use an app called PDF Lightweight to compress my PDFs (since I have made very good experiences) and Thunderbird to send emails.

I want to write an AppleScript that compresses PDFs before attaching them to an email:

```
set attachment1 to "/Users/username/Desktop/Test.pdf"

do shell script "open -a " & quoted form of ("/Applications/Lightweight PDF.app") & " " & quoted form of attachment1

set email_attachment to "attachment=" & "'file://" & attachment1 & "'"
set thunderbird_bin to "/Applications/Thunderbird.app/Contents/MacOS/thunderbird-bin -compose "
set arguments to email_attachment

do shell script thunderbird_bin & quoted form of arguments & ">/dev/null 2>&1 &"

```

The problem is that the original PDF will be attached before the compression finishes. I tried to work with something like [this](https://stackoverflow.com/questions/20146093/waiting-for-do-shell-script-to-finish) but it does not work either. I suppose because I start PDF Lightweight with an "open" command which is -technically- complete even when the app is still compressing.

Any ideas how get the script waiting for the PDF compression?

Thank you!

Answer: 
You could rewrite your hook to set the [fetch policy](https://www.apollographql.com/docs/react/data/queries/#configuring-fetch-logic) to 'no-cache' or 'network-only'

```
const [getResetLink, { loading, data }] = useLazyQuery(FORGOT_PASSWORD, {fetchPolicy: 'no-cache'})

```

On another note, you should consider using Mutation instead of Query for this operation, as probably there is some change in data. For example, you store the unique hash or link for resetting a password or something similar.
Alternatively you could use useQuery with skip option and the refetch result function. Refetch will always update the cache by default.

Something along these lines:

```
const { refetch: getResetLink, loading, data } = useQuery(FORGOT_PASSWORD, { skip: true } )

```

then in onSubmit `getResetLink({ email })`

<https://www.apollographql.com/docs/react/data/queries/#refetching>

> 
> A function that enables you to re-execute the query, optionally passing in new variables. To guarantee that the refetch performs a network request, its fetchPolicy is set to network-only (unless the original query's fetchPolicy is no-cache or cache-and-network, which also guarantee a network request)
> 
> 
>