How to Add an Animated Mascot to a macOS Menu Bar App in SwiftUI
By the Charmotion team · Updated · How we write guides

A macOS menu bar app gets its icon from a MenuBarExtra scene in SwiftUI, and the mascot lives in a window-style popover. Use a template image as the menu bar label, add the Rive SwiftUI runtime with Swift Package Manager, and load your .riv file with RiveViewModel. Then map app state to the mood input so the character reacts.
Key takeaways
- The window style of MenuBarExtra is the right place for an animated mascot, because the default menu style is a plain dropdown.
- Keep the menu bar label to a template image, since custom Shape or Color labels can render blank.
- Rive's SwiftUI runtime loads a .riv file with RiveViewModel, and its Apple guide lists macOS 13.1 as the minimum target.
- Drive the mascot with one mood number so app state maps to idle, happy, loading and the other states.
How do you add the Rive SwiftUI runtime to a macOS app?
Rive's SwiftUI runtime is part of its Apple runtime, distributed as the rive-ios Swift package. The same package supports UIKit and AppKit, so it works in a macOS target. Rive's runtimes are open source and play any .riv file. If the same mascot also ships in an iPhone build, see how to add animation to an iOS app.
- In Xcode, choose File, Add Package Dependencies, and enter https://github.com/rive-app/rive-ios.
- Set the dependency rule to version 6.24.0 or later, the minimum in Rive's official guide, and add the RiveRuntime product to your macOS target.
Rive's official guide says CocoaPods is in maintenance mode and recommends Swift Package Manager. If you define the dependency in a Swift package manifest, it looks like this:
dependencies: [
.package(url: "https://github.com/rive-app/rive-ios", from: "6.24.0")
],
targets: [
.target(
name: "MascotMenuBar",
dependencies: [
.product(name: "RiveRuntime", package: "rive-ios")
]
)
]
Drag your .riv file into the Xcode project and tick your macOS target so the file is bundled with the app. A Charmotion character export gives you one .riv file with a CharacterStateMachine, a number input named mood and a CharacterViewModelMachine, so you do not need to build a state machine by hand. Its paste-ready SwiftUI code uses the same runtime calls as the examples below. You can start from the Charmotion character builder.
How do you show the animated mascot in a popover?
The popover is the MascotPopover view, shown when the user clicks the menu bar icon. RiveViewModel loads the bundled file and gives you a view through .view(). This is the same pattern Rive's official iOS and macOS guide shows for SwiftUI.
import SwiftUI
import RiveRuntime
struct MascotPopover: View {
@ObservedObject var status: MascotStatus
@StateObject private var mascot = RiveViewModel(
fileName: "mascot",
stateMachineName: "CharacterStateMachine"
)
var body: some View {
VStack(spacing: 8) {
mascot.view()
.frame(width: 200, height: 200)
Button("Quit") {
NSApplication.shared.terminate(nil)
}
}
.padding(12)
}
}
The fileName is the .riv file name without its extension. The stateMachineName is the state machine to play, which is CharacterStateMachine in a character export. The accents boolean in the export hides the small Z, sparkle, thinking-dot and exclamation accents. Turn them off if they feel busy at popover size.
The popup size is yours to choose. This guide does not give a maximum size for the window-style popup, so test the frame on a small display before you ship it.
How do you change the mascot's mood from app state?
The mood numbers are fixed, so one value can drive the whole set. Moods blend into each other when the value changes. A character has no one-shot triggers, so show a success with happy and an error with sad.
| Mood | Number | Use in a menu bar app |
|---|---|---|
| idle | 0 | Default, nothing is running |
| happy | 1 | A task finished |
| wave | 2 | Greeting after first launch |
| thinking | 3 | Work in progress |
| sad | 4 | An error |
| loading | 5 | Sync or download running |
| listening | 6 | Waiting for the user |
| talking | 7 | Showing a reply or message |
| sleeping | 8 | Idle for a long time |
| attention | 9 | Needs the user's action |
Store the mood in an observable object that the app updates, then forward each change to the Rive view model.
final class MascotStatus: ObservableObject {
@Published var mood: Int = 0
}
// Add this modifier to the VStack in MascotPopover's body:
.onChange(of: status.mood) { newMood in
mascot.setInput("mood", value: Double(newMood))
}
The one-parameter onChange closure works on macOS 13. The two-parameter form needs macOS 14, so keep the one-parameter form if you target the minimum version.
Rive's data binding is the newer route. The export's CharacterViewModelMachine exposes the same mood as a number property, and Rive's data binding guide shows how to bind a view model instance to a state machine. Release 6.28.0 of rive-ios deprecated DataBind, the Rive initializer that accepts dataBind:, Rive.viewModelInstance and the singular bindViewModelInstance method. The same release redraws views automatically after changes to bound instances. For new code, follow the current data binding guide, and read Rive data binding in SwiftUI before you choose between the two approaches.
What should you check before shipping a menu bar mascot?
- Both menu bar appearances. Look at the template icon in light and dark menu bars, and on a crowded menu bar.
- The minimum macOS version. Build against macOS 13.1 or later and run the app on that version.
- Removal behavior. Remove the item from the menu bar and confirm the isInserted binding turns false and your app state matches.
- Popover size. Check the fixed frame on a small display, with accents on and off.
- Current icon guidance. This guide does not cite Apple point sizes for menu bar icons, so check Apple's current Human Interface Guidelines before you export the asset.
- Runtime version. Pin a version you have tested, and read the rive-ios release notes first, since release 6.28.0 changed the data binding APIs.
Motion can also be a problem for some users. Before you loop the mascot continuously, read Reduce Motion in SwiftUI and UIKit and decide what the character does when the setting is on.
For a larger set of mascot states in a windowed app, see the animated onboarding mascot in SwiftUI, and for the general Rive setup on Apple platforms, see how to use Rive in SwiftUI.
How to add an animated mascot to a macOS menu bar app in SwiftUI
- Set the deployment target. Set the macOS deployment target to 13.1 or later, the minimum listed in Rive's Apple runtime guide.
- Add the Rive runtime. Add https://github.com/rive-app/rive-ios with version 6.24.0 or later and link the RiveRuntime product to your macOS target.
- Bundle the .riv file. Drag your mascot .riv file into the Xcode project and tick the macOS target so the file ships inside the app.
- Create the menu bar label. Add a monochrome template image named MenuBarIcon, and use it as the MenuBarExtra label with isInserted bound to a Boolean.
- Build the popover. Apply .menuBarExtraStyle(.window) and show RiveViewModel(fileName:stateMachineName:).view() inside a fixed-size frame.
- Map app state to the mood. Store a mood number in an observable object and send it with setInput whenever it changes, using the mood table for idle, happy, loading and the other states.
Frequently asked questions
Can the mascot animate inside the menu bar icon itself?
Not with the approach in this guide. Text and template images render reliably in the menu bar label, while one reported custom label built from raw SwiftUI Shape or Color content rendered blank. Keep the icon static or switch between template images for each state, and run the Rive animation in the popover window.
Can the .riv file load from a web address instead of the app bundle?
Yes. Rive's official iOS and macOS guide shows RiveViewModel loading a .riv file from a web URL through a webURL argument. The app then needs network access to fetch the file on launch, so bundling the file is simpler for a menu bar utility that should work offline.
Why does my menu bar icon look wrong in dark mode?
Check that the image asset is a monochrome template and that the view uses renderingMode(.template). A full-color PNG keeps its original colors and can clash with a dark menu bar. Test both light and dark menu bars before release.
Should I install the Rive runtime with CocoaPods?
Rive's official Apple guide says CocoaPods is in maintenance mode and recommends Swift Package Manager. In Xcode, add https://github.com/rive-app/rive-ios through File, Add Package Dependencies, and select the RiveRuntime product.
Sources
- MenuBarExtra initializer (content and label), Apple Developer Documentation
- WWDC22 session 10061, Apple
- Rive Apple runtime, Rive
- Rive data binding for Apple runtimes, Rive
- rive-ios release 6.28.0, Rive (GitHub)
- Build a macOS menu bar utility in SwiftUI, Nil Coalescing