# Franklin.jl — automatically evaluate \`.jl\` file on change

**URL:** https://discourse.julialang.org/t/franklin-jl-automatically-evaluate-jl-file-on-change/92580
**Category:** General Usage
**Tags:** franklin
**Created:** [January 5, 2023, 10:53pm UTC](https://discourse.julialang.org/t/franklin-jl-automatically-evaluate-jl-file-on-change/92580 "2023-01-05T22:53:15Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![mpf01](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mpf01/32/8221_2.png) [@mpf01](https://discourse.julialang.org/u/mpf01)
#### Post date: [January 5, 2023, 10:53pm UTC](https://discourse.julialang.org/t/franklin-jl-automatically-evaluate-jl-file-on-change/92580/1 "2023-01-05T22:53:15Z")

</div>

I understand that Franklin’s [offline evaluation](https://franklinjl.org/code/#offline_evaluation_any_language) is meant to manually and outside of the live-evaluation workflow. Is there a way, however, to make Franklin watch for changes in a directory, and execute `generate_results.jl` anytime a file changes in a directory, or even better, execute `genplain("scriptname.jl")` each time `scriptname.jl` is updated?

---

<div class="post-metadata">

### Author: ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)
#### Post date: [January 6, 2023, 5:01am UTC](https://discourse.julialang.org/t/franklin-jl-automatically-evaluate-jl-file-on-change/92580/2 "2023-01-06T05:01:03Z")

</div>

Hey @mpf01 , may I ask what you are trying to do? I don’t know if Franklin does what you are saying but what I have done in the past is to deploy the Julia REPL, use FileWatching.jl, and then create an `@async` while loop that will trigger the execution of a script or function if a particular file or folder has detected a change.

---

<div class="post-metadata">

### Author: ![miguelraz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miguelraz/32/631_2.png) [@miguelraz](https://discourse.julialang.org/u/miguelraz)
#### Post date: [January 6, 2023, 6:09am UTC](https://discourse.julialang.org/t/franklin-jl-automatically-evaluate-jl-file-on-change/92580/3 "2023-01-06T06:09:18Z")

</div>

Share your code!

---

<div class="post-metadata">

### Author: ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)
#### Post date: [January 6, 2023, 10:01am UTC](https://discourse.julialang.org/t/franklin-jl-automatically-evaluate-jl-file-on-change/92580/4 "2023-01-06T10:01:24Z")

</div>

Possibly [Developer reference · Revise.jl](https://timholy.github.io/Revise.jl/stable/dev_reference/#Revise.add_callback) may be useful.

---

<div class="post-metadata">

### Author: ![tlienart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlienart/32/7640_2.png) [@tlienart](https://discourse.julialang.org/u/tlienart)
#### Post date: [January 6, 2023, 12:46pm UTC](https://discourse.julialang.org/t/franklin-jl-automatically-evaluate-jl-file-on-change/92580/5 "2023-01-06T12:46:00Z")

</div>

> [@mpf01](#):
>
> or even better, execute `genplain("scriptname.jl")` each time `scriptname.jl` is updated?

You may also want to consider doing something like [Generating auxiliary files with Literate](https://franklinjl.org/extras/literate/) . The literate path does check whether the underlying script changes.

---

<div class="post-metadata">

### Author: ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)
#### Post date: [January 7, 2023, 3:43am UTC](https://discourse.julialang.org/t/franklin-jl-automatically-evaluate-jl-file-on-change/92580/6 "2023-01-07T03:43:08Z")

</div>

Sure! Here is an example on how I do this:

```julia
using FileWatching

@async while true 
    watch_file("./tmp.jl")
    println("Change Detected!")
end

```

This creates an asynchronous task in the background of your Julia REPL that can then run whatever command you want while you monitor a specific file (or folder). In this case, I am making the task print a statement that says “Change Detected!” to my REPL whenever there is a change in the file called “tmp.jl”. Here is a video showing blocking and asynchronous behavior:

![watching_example](https://global.discourse-cdn.com/julialang/original/3X/8/0/808f3df5a9d1ba4b9f5b8a546c6ef5eb2ca5cddc.gif)

I also use this same process when working with Weave to generate Weave on a change and then I use the node package, browser-sync, to reload my browser upon change to view my Weave made report. Happy to share that too!

---

<div class="post-metadata">

### Author: ![mpf01](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mpf01/32/8221_2.png) [@mpf01](https://discourse.julialang.org/u/mpf01)
#### Post date: [January 7, 2023, 7:24pm UTC](https://discourse.julialang.org/t/franklin-jl-automatically-evaluate-jl-file-on-change/92580/7 "2023-01-07T19:24:08Z")

</div>

Great solution, @TheCedarPrince. Thanks!

---

<div class="post-metadata">

### Author: ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)
#### Post date: [January 8, 2023, 7:58pm UTC](https://discourse.julialang.org/t/franklin-jl-automatically-evaluate-jl-file-on-change/92580/8 "2023-01-08T19:58:11Z")

</div>

No problem and glad I could help!

I decided to write a full blog post on this answer here: [Asynchronous Workflow Using Julia Tutorial](https://jacobzelko.com/01082023043553-julia-async-workflow/)

Feel free to give it a look!

---

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [April 13, 2024, 7:39pm UTC](https://discourse.julialang.org/t/franklin-jl-automatically-evaluate-jl-file-on-change/92580/9 "2024-04-13T19:39:08Z")

</div>

I know it’s an old topic, but, maybe [Pluto](https://plutojl.org) helps?
